3 Answers
+ 2
from time import time
N = 2**32
M = 1664525
C = 1013904223
def rand(a, b):
'''
Linear congruential random generator
'''
random = hash(time())
while True:
random = a + ((M*random + C) % N) % (b-a)
yield random
def test_rand(numtests, a, b):
print('{0} random numbers in range({1}, {2}):'.format(numtests, a, b))
for i in range(numtests):
print(next(rand(a, b)))
if __name__ == '__main__':
test_rand(10, 0, 100)
Algo from here: https://en.wikipedia.org/wiki/Linear_congruential_generator
+ 1
What numbers does it have to generate (integers, floats in range(a,b) etc.)?
And why not using random module? Is it your home task? Or because of security issues and the generator has to use smth else instead of time for producing random numbers?
0
yes its my assignment
i have to generate integers
please provide code and algo



