Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random as random
- from math import floor
- def myfunc(n):
- '''output estimated dice probabilities'''
- probabilities = [0]*6
- def update():
- '''Toss a dice in the air, update the estimated probability'''
- roll_i = random.uniform(0,1)
- idx = int(floor(roll_i*6)) # Map to 0, 1, 2, 3, 4, 5 with equal probability
- probabilities[idx]+=1.0/n
- [update() for i in range(n)]
- return probabilities
- prob = myfunc(100000)
- print(prob)
Advertisement
Add Comment
Please, Sign In to add comment