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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -