Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Checks longest run lengths in n attempts of n flips
- import random
- attempts = 10000
- results = {}
- while attempts != 0:
- attempts -= 1
- maxRun = 0
- last = -1
- count = 0
- flips = 200
- while flips != 0:
- flips -= 1
- num = random.randint(0,1)
- if last == -1:
- last = num
- count += 1
- elif num == last:
- count += 1
- else:
- if count > maxRun:
- maxRun = count
- count = 1
- if maxRun in results:
- results[maxRun] += 1
- else:
- results[maxRun] = 1
- for key, value in results.items():
- print(key, value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement