random - Actually run a function a certain percentage of the time in PHP -
how can write function in php call given function (anonymous) x%
of time?
for example:
function call_weighted(0.1, function() { echo 'this run approximately 10% of times called'; });
function call_weighted($weight, $function) { if (mt_rand() < $weight * mt_getrandmax()) { $function(); } }
Comments
Post a Comment