Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from bisect import bisect_left
- from collections import Counter
- def rand(start, F):
- return start + bisect_left(F, random.random())-1
- def normalisedCumu(fs):
- tot = sum(fs)
- ret = [0]
- cumu = 0
- for v in fs:
- cumu += v
- ret.append(cumu/tot)
- return ret
- ### Test ###
- #ps = [0, 0.3, 0.4, 1]
- start = 70
- F = normalisedCumu([1]*10 + [0]*3 + [1]*4)
- simuN = 10000
- d = Counter([rand(start, F) for _ in range(simuN)])
- for k in sorted(d.keys()):
- print (k, ": ", float(d[k])/simuN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement