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 Quote Link to comment 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; } Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.