A simple php lucky draw applet

Source: Internet
Author: User
An introduction to a lucky draw applet is controllable, and a prize can be displayed on the front end, which is impossible to be obtained in the program. after adding all the probability x10, the value of each item in the new array is equal to the sum of the first few items plus itself, and then a number between 0 and the maximum number is generated... an introduction to a lucky draw applet is controllable, and a prize can be displayed on the front end, which is impossible to be obtained in the program. after adding all the probability x10, the value of each item in the new array is equal to the sum of the first few items plus itself, and then a number between 0 and the maximum number is generated. you can view the range in a loop, return the key of the interval. the code is as follows:

 3.5, // 3.5% probability 2 => 2.5, 3 => 6, 4 => 2, 5 => 42, // 42% probability 6 => 36, 7 => 2, 8 => 4, 9 => 2); // finally confirm that the sum is equal to 100 $ prizeList = array (1 => array ('fairy '), 2 => array ('5q coin '), 3 => array ('000000'), 4 => array ('000000 '), 5 => array ('thank you for your participation! '), 6 => array (' welcome to come back next time! '), 7 => array ('10q coin'), 8 => array ('1970 silver ingot (bound) '), 9 => array ('random advanced mounts (bound) '); // unset ($ prize [7]); directly remove the 10Q prize $ times = 10; $ max = 0; foreach ($ prize as $ k =>$ v) {$ max = $ v * $ times + $ max; $ row ['V'] = $ max; $ row ['K'] = $ k; $ prizeZone [] = $ row;} $ max --; // critical value $ rand = mt_rand (0, $ max ); $ zone = 1; foreach ($ prizeZone as $ k = >$ v) {if ($ rand >=$ v ['V']) {if ($ rand >=$ prizeZone [$ k + 1] ['V']) {co Ntinue;} else {$ zone = $ prizeZone [$ k + 1] ['K']; break; }}$ zone = $ v ['K']; break ;} print_r ($ prizeList [$ zone] [0]);?>

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.