ComputationalPhysics300 icon indicating copy to clipboard operation
ComputationalPhysics300 copied to clipboard

Random number generation

Open qzhu2017 opened this issue 5 years ago • 0 comments

The choice of m seems to generate very interesting phenomena.

%matplotlib inline
import matplotlib.pyplot as plt 
# We can only change [a , c , m]
N = 1000
a = 3125 #57
c = 19*17 #287
m = 10.99
x = 1
# This shows that a has to be in range 40<a<60 and c has to be in range of 200<c<300 for it to be somewhat random
results = []

for i in range(N):      
    x = (a*x+c)%m -5
    results.append(round(x))
plt.plot(results,"o")
plt.show()
plt.hist(results, bins=10)

qzhu2017 avatar Oct 24 '18 23:10 qzhu2017