Last active
March 14, 2018 13:48
-
-
Save AndyNovo/a0c2d34595d32b43ed9f98bb2fa5ab64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def crand(seed): | |
r=[] | |
r.append(seed) | |
for i in range(30): | |
r.append((16807*r[-1]) % 2147483647) | |
if r[-1] < 0: | |
r[-1] += 2147483647 | |
for i in range(31, 34): | |
r.append(r[len(r)-31]) | |
for i in range(34, 344): | |
r.append((r[len(r)-31] + r[len(r)-3]) % 2**32) | |
while True: | |
next = r[len(r)-31]+r[len(r)-3] % 2**32 | |
r.append(next) | |
yield (next >> 1 if next < 2**32 else (next % 2**32) >> 1) | |
my_generator = crand(123) | |
for i in range(5): | |
print my_generator.next() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment