The PHP lottery algorithm is now available for a lottery activity & nbsp; the probability of winning the prize is as follows: First Prize 5% second prize 10% third prize 60% participation prize 25% my thoughts are very stupid: I have a random number ranging from 0 to, and then divide the interval according to the winning probability & nbsp; first prize 96-100 second prize 86-95 third prize 26-85 participation prize 1-25 not touched on the PHP lottery algorithm
Now we want to make a lucky draw.
The winning probability is as follows:
First prize: 5%
Second prize 10%
Third Prize: 60%
Participation 25%
My thoughts are stupid:
I random a number ranging from 0 to and divide the interval based on the winning probability.
First prize 96-100
Second prize 86-95
Third Prize 26-85
Participation prize 1-25
I have never touched on algorithms. please help me.
------ Solution --------------------
This idea is acceptable.
PHP code
'First Run', 10 => 'second run', 60 => 'third running', 25 => 'participate in the prize '); $ pool = array (); foreach ($ arr as $ k => $ v) // Construct prize pool $ pool + = array_fill (count ($ pool), $ k, $ v ); echo $ pool [rand ()]; // start drawing