Created
April 26, 2023 08:06
-
-
Save knot126/fd0b34c6ab6d9db395059db751a41dc4 to your computer and use it in GitHub Desktop.
This file contains 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 lcg(a, x, b, m): | |
return (a * x + b) % m | |
def main(): | |
print("Please select parameters to test with.") | |
a = eval(input("a = ")) | |
b = eval(input("b = ")) | |
m = eval(input("m = ")) | |
s = eval(input("s_0 = ")) | |
x = s | |
i = 0 | |
before = [] | |
while (True): | |
x = lcg(a, x, b, m) | |
print(f"[{i}] -> {x}") | |
if (x in before): | |
break | |
before.append(x) | |
i += 1 | |
print(f"Repeated after {i + 1} iterations.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment