Last active
August 29, 2015 14:23
-
-
Save vgmoose/5e757235e039a1d88aa0 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
import random, hashlib, sys | |
from collections import defaultdict | |
try: | |
import matplotlib.pyplot as plt | |
matlab = True | |
except: | |
print("you will need to install http://matplotlib.org/users/installing.html to display the graph") | |
matlab = False | |
def main(): | |
init = raw_input("Input initial value: ") | |
tries = raw_input("Number of trials? ") | |
sys.setrecursionlimit(100000) | |
out = do_the_thing(init, int(tries)) | |
print out | |
if matlab: | |
plot_the_thing(out) | |
def do_the_thing(seed, count): | |
# Hash teh value | |
m = hashlib.md5() | |
m.update(seed) | |
hsh = m.digest() | |
# seed a new prando gen | |
random.seed(hsh) | |
value = random.random()*100 | |
# print that new value | |
#print(value) | |
value = int(value) | |
# dat base case | |
if count <= 0: | |
graph = defaultdict(int) | |
graph[value] = graph[value] + 1 | |
return graph | |
# recurse | |
graph = do_the_thing(hsh, count-1) | |
graph[value] = graph[value] + 1 | |
return graph | |
def plot_the_thing(thing): | |
plt.bar(range(len(thing)),thing.values(), align="center") | |
plt.show() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment