Lottery probability
Lottery probability
$ ProCur) {$ randNum = mt_rand (1, $ proSum); if ($ randNum <= $ proCur) {$ result = $ key; break ;} else {$ proSum-= $ proCur ;}} unset ($ proArr); return $ result ;} $ prize_arr = array ('0' => array ('id' => 1, 'prize' => 'tablet ', 'V' => 0 ), '1' => array ('id' => 2, 'prize' => 'digital camera ', 'V' => 0 ), '2' => array ('id' => 3, 'prize' => 'Speaker device', 'V' => 0 ), '3' => array ('id' => 4, 'prize' => '4G disks', 'V' => 0 ), '4' => array ('id' => 5, 'prize' => '10q coin ', 'V' => 1 ), '5' => array ('id' => 6, 'prize' => 'next time you may be able to get in,', 'V' => 100 ),); // code here eg: unset ($ prize_arr ['0']) foreach ($ prize_arr as $ key => $ val) {$ arr [$ val ['id'] = $ val ['V'];} $ rid = get_rand ($ arr ); // Obtain the award id $ res ['yes'] = $ prize_arr [$ rid-1] ['prize'] based on the probability. // Medium Award // remove the Medium Award from the array, and the remaining ones are not in progress. for database verification, unset ($ prize_arr [$ rid-1]) can be saved here; shuffle ($ prize_arr); // disrupt the array order for ($ I = 0; $ I
"; Print_r ($ res); // echo json_encode ($ res );
2. [code] lottery probability
$ ProCur) {$ randNum = mt_rand (1, $ proSum); if ($ randNum <= $ proCur) {$ result = $ key; break ;} else {$ proSum-= $ proCur ;}} unset ($ proArr); return $ result ;} $ prize_arr = array ('0' => array ('id' => 1, 'prize' => 'tablet ', 'V' => 0 ), '1' => array ('id' => 2, 'prize' => 'digital camera ', 'V' => 0 ), '2' => array ('id' => 3, 'prize' => 'Speaker device', 'V' => 0 ), '3' => array ('id' => 4, 'prize' => '4G disks', 'V' => 0 ), '4' => array ('id' => 5, 'prize' => '10q coin ', 'V' => 1 ), '5' => array ('id' => 6, 'prize' => 'next time you may be able to get in,', 'V' => 100 ),); // code here eg: unset ($ prize_arr ['0']) foreach ($ prize_arr as $ key => $ val) {$ arr [$ val ['id'] = $ val ['V'];} $ rid = get_rand ($ arr ); // Obtain the award id $ res ['yes'] = $ prize_arr [$ rid-1] ['prize'] based on the probability. // Medium Award // remove the Medium Award from the array, and the remaining ones are not in progress. for database verification, unset ($ prize_arr [$ rid-1]) can be saved here; shuffle ($ prize_arr); // disrupt the array order for ($ I = 0; $ I
"; Print_r ($ res); // echo json_encode ($ res );
The above is the content of the lucky draw probability. For more information, see The PHP Chinese website (www.php1.cn )!