Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Rolling a biased die

by abell (Chaplain)
on Apr 12, 2002 at 10:39 UTC ( #158540=note: print w/replies, xml ) Need Help??


in reply to Rolling a biased die

Say you have n values with probabilities d_1, ..., d_n. Normalize your values so that all d_i's are at least 1. Then you can do with O(sum(d_i)) storage and O(1) time. For each integer l less than sum(d_i) there is at most one transition from one d_i to the next one between l and l+1. For each l, just store either the outcome which covers all the l-th unit interval or the two outcomes and the transition point.
It's not the most elegant solution and in case you have very small values you may think of some variation, but in your case it should work quite well.
Best regards

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://158540]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2019-10-13 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?