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 value of the first few
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:
- $ Prize = array (
- 1 => 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 100
- $ PrizeList = array (
- 1 => array ('Little fairy '),
- 2 => array ('5q coin '),
- 3 => array ('100 game coin '),
- 4 => array ('88888 game coin '),
- 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]); remove the 10Q prize directly.
- $ 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'])
- {
- Continue;
- }
- Else
- {
- $ Zone = $ prizeZone [$ k + 1] ['K'];
- Break;
- }
- }
- $ Zone = $ v ['K'];
- Break;
- }
- Print_r ($ prizeList [$ zone] [0]);