Skip to content

Instantly share code, notes, and snippets.

@knot126
Created April 26, 2023 08:06
Show Gist options
  • Save knot126/fd0b34c6ab6d9db395059db751a41dc4 to your computer and use it in GitHub Desktop.
Save knot126/fd0b34c6ab6d9db395059db751a41dc4 to your computer and use it in GitHub Desktop.
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