Skip to content

Instantly share code, notes, and snippets.

@honno
Last active Feb 8, 2021
Embed
What would you like to do?
Stupid simple Mersenne Twister.
class Mersenne:
def __init__(self, seed=1234):
self.seed = seed
self.j = 2 ** 31 - 1
self.k = 16807
self.period = 2 ** 30
def __iter__(self):
return self
def __next__(self):
self.seed = (self.k * self.seed) % self.j
if self.seed / self.j < 0.50:
return 0
else:
return 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment