In my script I want to run certain code a certain percent of the time, I’ve looked around StackOverflow and found the code below. It runs the code 33% of the time, what do I need to modify to get it to run 55% and 70% of the time?
$max = 27;
for($i = 1; $i < $max; $i++){
if($i % 3 == 0){
call_function_here();
}
}
Easiest way is to use a random number generator and test that its result is less than (or greater than, doesn’t matter) the amount you’re targeting for.