如何根据事件发生的概率在php中执行一个事件

如何根据事件发生的概率在php中执行一个事件,php,probability,Php,Probability,我想要这样的东西: $chance = 40; //40% if ( run the probability check script ) { echo "event happened"; //do the event } else { echo "event didn't happened"; } 实现这一目标的最佳解决方案是什么 非常感谢 使用: 如果(兰特(1100)嗯……要么我丢了,要么你是说你想要下面的 $chance = 40; if ($chance >= 4

我想要这样的东西:

$chance = 40; //40%
if ( run the probability check script ) {
    echo "event happened"; //do the event
}
else {
   echo "event didn't happened";
}
实现这一目标的最佳解决方案是什么

非常感谢

使用:


如果(兰特(1100)嗯……要么我丢了,要么你是说你想要下面的

$chance = 40;
if ($chance >= 40){
    echo "event happened"; //do the event
} else {
   echo "event didn't happened";
}
这假设机会等于或大于40

如果您希望随机生成chance,那么对0到100之间的随机数使用类似于
$chance=rand(0100);
的语句,然后只使用If语句来实现这些条件


在一天结束时,这取决于你的初始概率是一个固定的数字,还是随机的,或者是计算的结果……不幸的是,你没有提供太多的见解……

取决于“概率检查脚本”,那么一般的概率计算呢?所以$chance可能=0.1%,或0.0001%或1500%。
$chance = 40;
if ($chance >= 40){
    echo "event happened"; //do the event
} else {
   echo "event didn't happened";
}