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
- for i in range(n):
- 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
- return probabilities
- prob = myfunc(10000)
- print(prob)
Advertisement
Add Comment
Please, Sign In to add comment