PHP-based simple random draw small program, PHP draw applet _php Tutorial

Source: Internet
Author: User

PHP-based simple random draw small program, PHP draw small Program


A lottery small program, introduction can be controlled, can also be a prize in front of the display, and the program is impossible to obtain! After all the probabilities are x10 together, the value of each item in the new array equals its first few and adds itself.

A number between 0 and the maximum number is then generated, and a loop to see if it belongs to that interval and returns the key for that 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 =, 7 = 2, 8 = 4 , 9 = 2);//Final confirmation add equals 100$prizelist = Array (1 = = Array (' Little Fairy '), 2 = = Array (' 5Q coins '), 3 = = Array (' 38888 game Coins '), 4 => ; Array (' 88888 game Coins '), 5 = = Array (' Thanks for participating! '), 6 = = Array (' Welcome to come again next time! '), 7 = = Array (' 10Q coins '), 8 = = Array (' 888 Silver dollar (binding) '), 9 = = Array (' Random advanced mounts (Bindings) '));//unset ($prize [7]); 10Q This prize directly removed $times = ten; $max = 0;foreach ($prize as $k = + $v) {$max = $v * $times + $max; $row [' V '] = $max; $row [' k '] = $k ; $prizeZone [] = $row;} $max--; The threshold value $rand = Mt_rand (0, $max), $zone = 1;foreach ($prizeZone as $k = = $v) {if ($rand >= $v [' V ']) {if ($rand >= $priz ezone[$k + 1][' V ']) {continue;} else{$zone = $prizeZone [$k + 1][' K '];break;}} $zone = $v [' K '];break;} Print_r ($prizeList [$zone][0]);

PHP based on the implementation of a simple draw small program code for everyone to write so much, but are the core code, I hope to learn from you to help.

Articles you may be interested in:

    • PHP Draw Small Program implementation code
    • PHP implementation can set the winning probability of the Lottery program code sharing
    • PHP probabilistic algorithm for lottery programs and random ads
    • PHP solves the problem of stock negative caused by high traffic and storage in the second-kill lottery
    • PHP Carousel Draw Interface Example
    • Probabilistic algorithm for winning lottery programs written by PHP

http://www.bkjia.com/PHPjc/1088781.html www.bkjia.com true http://www.bkjia.com/PHPjc/1088781.html techarticle based on PHP implementation of a simple random draw small program, PHP draw small program A lottery small program, introduction controllable, can also be a prize in the front display, and the program is not possible to obtain! Take the place of ...

  • 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.