[英]Actually run a function a certain percentage of the time in PHP
如何在PHP中编写函数以X%
的时间调用给定函数(匿名)?
例如:
function call_weighted(0.1, function() {
echo 'this is actually run approximately 10% of the times it is called';
});
function call_weighted($weight, $function) {
if (mt_rand() < $weight * mt_getrandmax()) {
$function();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.