I have to implement the Wichmann-Hill random number generation algorithm in python (3.x) for an assignment. The algorithm needs to be seeded with three random numbers.
I tried seeding it with time.time_ns()
, but if I try generating a new number many times in a row (I have to be able to do at least 100 000 consecutively) I get a bunch of repetitions because evidently the time hasn't changed yet.
The algorithm for Wichmann-Hill is as follows:
i1 = (170 * i1) % 30323
i2 = (171 * i2) % 30269
i3 = (172 * i3) % 30307
i1 = i1 / 30323.0
i2 = i2 / 30269.0
i3 = i3 / 30307.0
return (i1 + i2 + i3) % 1.0
Where i1, i2 and i3 are supposed to be the seeds.
I'm stuck on finding a way to seed the algorithm for the next time a number is needed. Any advice is much appreciated.