Home > php教程 > php手册 > php抽奖概率|php概率实现|ProbobAward

php抽奖概率|php概率实现|ProbobAward

WBOY
Release: 2016-06-06 19:38:55
Original
1489 people have browsed it

$award = array( 1 = 1, 2 = 3, 3 = 6, 4 = 9, 5 = 12, 6 = 22, 7 = 30, 8 = 50, 9 = 60, 10 =99 ); echogetProbobAward($award); 无 ?phpdefined('ROOT') or exit('Access Denied');class Probob{public function getProbobAward($array){$Sum = array_sum($

$award = array(
1 => 1,
2 => 3,
3 => 6,
4 => 9,
5 => 12,
6 => 22,
7 => 30,
8 => 50,
9 => 60,
10 => 99
);
echo getProbobAward($award);
<?php
defined('ROOT') or exit('Access Denied');

class Probob{
	
	public function getProbobAward($array){
		$Sum = array_sum($array);
		foreach($array as $key => $prob){
			$Rand = mt_rand(1, $Sum);
			if($Rand <= $prob){
				return $key;
			}else{
				$Sum -= $prob;
			}
		}
	}
		
}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template