Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import datetime
- start = datetime.datetime.now()
- runs = 10 ** 6
- i = 0
- seed = datetime.datetime.utcnow()
- seed = seed.hour * seed.minute + seed.second
- random.seed(seed)
- sequence = []
- stack = [0,1,0,1,0,1,0,1,0,1]
- def normal():
- return 0
- def rand():
- return random.randint(0,1)
- def regress():
- s = sum(stack[-4:])
- if s == 2: # coin flip is the only fair thing
- return random.randint(0,1)
- elif s > 2:
- return 0
- else:
- return 1
- def regressLong():
- s = sum(stack)
- if s == 5: # coin flip is the only fair thing
- return random.randint(0,1)
- elif s > 5:
- return 0
- else:
- return 1
- jumpy = [('normal', normal), ('rand', rand), ('regress', regress), ('regressLong', regressLong)]
- results = dict(normal=0,rand=0,regress=0,regressLong=0)
- last = 0
- for x in range(0, runs):
- y = random.randint(0,1)
- for n,f in jumpy:
- if f() == y:
- results[n] += 1
- i += y
- last = y
- stack.append(y)
- stack = stack[1:]
- if x % 100000 == 0:
- print 'Done %i runs' % x
- for k,v in results.iteritems():
- print 'Variable {k} was successful {t} of the time'.format(k=k, t=v*100.0/runs)
- print(i)
- end = datetime.datetime.now()
- print end - start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement