Write a program to implement Linear Congruential Generators in python



a = 5
c = 3
z0 = 7
m = 16
zp = z0
n = []
i = 0
#def mainfunc():
while i<5: #5 is the number of random numbers
    zi = (a*zp+c)%m
    zp = zi

    if zi in n:
            #print(len(n))
        break
    #n1 = yield zi
    n.append(zi)
        #n.append(n1)
    i = i+1

print "Random Numbers are : "
for i in range(0,len(n)):
    print n[i]


#-------Output-------------
Random Numbers are :
6
1
8
11
10

No comments:

Post a Comment