Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Rolling a biased die

by tomazos (Deacon)
on Apr 13, 2002 at 13:56 UTC ( [id://158773]=note: print w/replies, xml ) Need Help??


in reply to Re: Rolling a biased die
in thread Rolling a biased die

Cool algorithm. It's like a king of the hill match.

1 starts as king of the hill. ($rand = 1)

2 comes along and challanges it. Whoever wins stays on top (is assigned to $rand).

Just like 2, everyone else (3, 4, 5 and 6) gets a chance.

Whoever is left on top ($rand) is declared the winner. :)


To understand why the probabilities work you have to step through the algorithm backwards.

ie. What is the chance that 6 (the final iteration) is going to win it's match against the king of the hill? $bias{6} / sum(values %bias), which is obvious.

Now - consider the second last iteration (5). Given that 6 is going to have it's chance in a minute, and hence does not need to be included, what is the chance that 5 will win it's match? $bias{5} / (sum(values %bias) - $bias{6}). We remove 6 from the running by excluding it's weighting from the total.

Update: This explanation is awful. :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found