Skip to content

Instantly share code, notes, and snippets.

@redspider
Created December 15, 2017 07:06
Show Gist options
  • Save redspider/4f2c27e3bf6b9e1f3bf13910bf961647 to your computer and use it in GitHub Desktop.
Save redspider/4f2c27e3bf6b9e1f3bf13910bf961647 to your computer and use it in GitHub Desktop.
def generator(start, factor, multiple = 1):
previous = start
while True:
n = previous * factor % 2147483647
previous = n
if n % multiple == 0:
yield n
A = generator(116, 16807, 4)
B = generator(299, 48271, 8)
count = 0
for i in range(0, 5000000):
count += next(A) & 0xffff == next(B) & 0xffff and 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment