如何在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();
}
}