I try to make a pseudo-random number generator using Linear Congruential Generator.
Here is my code I wrote using Python:
x = [43334] # this is the initial seed
a = 7**5
c = 0
m = (2**31)-1
for i in range(20):
xn = ((a*x[i])+c)%m
x.append(xn)
u = x[i]/(m-1)
print(int(u*5)+1)
I got the result as shown below:
1
2
1
3
1
5
2
4
5
4
5
4
2
1
1
4
1
3
3
5
I need to print 1 number only and give different result every time it print the result, any ideas?
Aucun commentaire:
Enregistrer un commentaire