Created
March 8, 2011 13:34
-
-
Save chooper/860260 to your computer and use it in GitHub Desktop.
A 'broken' Random Number Generator. Always throws 2 after 6
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
#!/usr/bin/env python | |
from random import randint | |
class BrokenRNG(): | |
"""A 'broken' Random Number Generator. Always throws 2 after 6""" | |
last_state = None | |
def __iter__(self): | |
return self | |
def next(self): | |
if self.last_state == 6: | |
self.last_state = 2 | |
else: | |
self.last_state = randint(1,10) | |
return self.last_state | |
if __name__ == '__main__': | |
for i in BrokenRNG(): | |
print i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment