bachx Posted February 26, 2007 Share Posted February 26, 2007 Ok, I want to write a certain code, where that code would have a certain percentage of executing/not executing For example, I want the following operation: $x = $x + 1 To have a chance of 37% to execute, and 63% not to execute. I hope I made myself clear. Thanks in Advance Link to comment https://forums.phpfreaks.com/topic/40118-solved-php-and-percentages/ Share on other sites More sharing options...
Jessica Posted February 26, 2007 Share Posted February 26, 2007 $chance = rand(1,100); if($chance > 63){ $x = $x+1; } Link to comment https://forums.phpfreaks.com/topic/40118-solved-php-and-percentages/#findComment-194100 Share on other sites More sharing options...
fert Posted February 26, 2007 Share Posted February 26, 2007 $a=range(0,36); $num=rand(0,100); if(in_array($num,$a)) { $x = $x + 1 } would also work Link to comment https://forums.phpfreaks.com/topic/40118-solved-php-and-percentages/#findComment-194103 Share on other sites More sharing options...
magnetica Posted February 26, 2007 Share Posted February 26, 2007 $chance = rand(1,100); if($chance > 63){ $x = $x+1; } Thanks you helped me out too. This will be quite useful for the future Link to comment https://forums.phpfreaks.com/topic/40118-solved-php-and-percentages/#findComment-194105 Share on other sites More sharing options...
bachx Posted February 26, 2007 Author Share Posted February 26, 2007 Thanks for the fast replies guys. That's one nice community in here! Link to comment https://forums.phpfreaks.com/topic/40118-solved-php-and-percentages/#findComment-194108 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.