Barevný test generátoru náhodných čísel¶
In [11]:
import numpy as np
import matplotlib.pyplot as plt
čistě multiplikativní lineární kongruentní generátor
$I_{j+1}=aI_j\; (\text{mod } m)$
$a = 16807$, $m = 2^{31}-1$
In [12]:
def ran0(i):
#RAN0
a=16807
m=2147483647
#RANDU
#a=65539
#m=2147483648
i=(a*i) % m
return i,i/m
In [13]:
i=123456789
N=1000000
x=np.empty(N)
y=np.empty(N)
RGB=np.empty([N,3])
for j in range(N):
i,x[j]=ran0(i)
i,y[j]=ran0(i)
i,RGB[j,0]=ran0(i)
i,RGB[j,1]=ran0(i)
i,RGB[j,2]=ran0(i)
In [14]:
fig,ax=plt.subplots(figsize=(10,10))
ax.scatter(x,y,c=RGB,s=0.1)
ax.set_xlim(0,1)
ax.set_ylim(0,1)
plt.show()
IBM generátor RANDU
$I_{j+1}=aI_j\; (\text{mod } m)$
$a = 65539$, $m = 2^{31}$
In [15]:
def randu(i):
a=65539
m=2147483648
i=(a*i) % m
return i,i/m
In [16]:
i=123456789
N=1000000
x=np.empty(N)
y=np.empty(N)
RGB=np.empty([N,3])
for j in range(N):
i,x[j]=randu(i)
i,y[j]=randu(i)
i,RGB[j,0]=randu(i)
i,RGB[j,1]=randu(i)
i,RGB[j,2]=randu(i)
In [17]:
fig,ax=plt.subplots(figsize=(10,10))
ax.scatter(x,y,c=RGB,s=0.1)
ax.set_xlim(0,1)
ax.set_ylim(0,1)
plt.show()