Questions about the PHP lottery algorithm

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.