samedi 23 mai 2020

PDF of numbers from linear congruential random numbers

I am writing a python code to create a probability distribution of numbers generated by the Linear Congruential random numbers between 0 and 1. I am not getting the density plot I expected. Shoudn't it be a rectangle of height 1 and span in x from 0 to 1?

import numpy as np
import matplotlib.pyplot as plt

m=2**31       #these numbers are same as used by C in rand()
a=1103515245
c=12345
n = 10000
x = np.zeros(n)
x[0]=1          #Seed

for i in range(n-1):
    x[i+1] = ((a*x[i]+c)%m)/m   #Divided by m so that numbers are scaled to the range [0,1]

plt.hist(x,density=True)
plt.show()



Aucun commentaire:

Enregistrer un commentaire