Home > php教程 > php手册 > 中奖率算法,方便修改中奖率

中奖率算法,方便修改中奖率

WBOY
Release: 2016-06-06 19:35:23
Original
1610 people have browsed it

如果有更好的,可以互相交流多谢 优势:新增和删除奖项以及修改概率都很方便。 公式:随机数=(概率+前面所有概率)*总数 WCMS ?php//配置说明//$gailv 1为1等奖的概率,2为等奖的概率//$base 为基数 百分之几概率 //@autor wolf Email 116311316@qq.com//概率算

如果有更好的,可以互相交流 多谢  
优势:新增和删除奖项以及修改概率都很方便。
公式:随机数 .CodeEntity .code_pieces ul.piece_anchor{width:25px;position:absolute;top:25px;left:-30px;z-index:1000;} .CodeEntity .code_pieces ul.piece_anchor li{width:25px;background: #efe;margin-bottom:2px;} .CodeEntity .code_pieces ul.piece_anchor li{border-left:3px #40AA63 solid;border-right:3px #efe solid;} .CodeEntity .code_pieces ul.piece_anchor li:hover{border-right:3px #40AA63 solid;border-left:3px #efe solid;} .CodeEntity .code_pieces ul.piece_anchor li a{color: #333;padding: 3px 10px;} .CodeEntity .code_pieces .jump_to_code{visibility:hidden;position:relative;} .CodeEntity .code_pieces .code_piece:hover .jump_to_code{visibility:visible;} .CodeEntity .code_pieces .code_piece:hover .jump_to_code a{text-decoration:none;} .CodeEntity .code_pieces h2 i{float:right;font-style:normal;font-weight:normal;} .CodeEntity .code_pieces h2 i a{font-size:9pt;background: #FFFFFF;color:#00A;padding: 2px 5px;text-decoration:none;}
<?php
//配置说明
//$gailv 1为1等奖的概率,2为等奖的概率
//$base 为基数 百分之几概率 
//@autor wolf Email 116311316@qq.com
//概率算法
$gailv = array (1 => 0.02, 2 => 0.1, 3 => 0.3, 4 => 0.5, 0 => NULL );

//根据最小的中奖率设置 百分比 千分比 万分比
$base = 100;
$randNum = rand ( 1, $base );

$reward = 0; //默认不中奖 几等奖
//随机数<=(概率+前面所有概率)*总数
$before = 0;
foreach ( $gailv as $k => $v ) {
	if ($randNum <= ($v + $before) * $base) {
		$reward = $k;
		break;
	}
	$before += $v;

}
echo $reward;
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