samedi 23 septembre 2017

how to make your customised rand function in python

I want to make a random number generator

So i did a lot of research and made a small code below

a=1
b=2
m=5000
x=3
lst=[]
for i in range(10):
  x=(a*x+b)%m
  lst.append(x)
print(lst)
if len(lst) != len(set(lst)):
    print("it has duplicates but possibly random numbers")
else:
    print("those were random numbers")

The mathematical equation I got from here It gives me some random number but only when the values are big, if i chose small values(Suppose m=5,keeping rest of the values same) i can see a repeated number series is getting formed.

* Question*

I can see from here python gets it from OS it doesn't generate them So is it the correct way to generate random number in python ??




Aucun commentaire:

Enregistrer un commentaire