Skip to content

Instantly share code, notes, and snippets.

@vgmoose
Last active Aug 29, 2015
Embed
What would you like to do?
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