我想要这样的东西:
$chance = 40; //40%
if ( run the probability check script ) {
echo "event happened"; //do the event
}
else {
echo "event didn't happened";
}
Run Code Online (Sandbox Code Playgroud)
实现类似目标的最佳解决方案是什么?
非常感谢!
Dor*_*mer 22
使用rand():
if (rand(1,100)<=$chance)
Run Code Online (Sandbox Code Playgroud)
这将返回1到100之间的数字,因此它低于或等于40的概率是40%.