Pathogen Posted July 26, 2009 Posted July 26, 2009 How would I create a random number generator to use in a if statement? rand(0-100) Is that how you do it? Quote
Dave Posted July 27, 2009 Posted July 27, 2009 Re: How Would I do this? Firstly you will probably want to use mt_rand i beleive its quicker then the standard rand And to use a mt_rand in a if statement i beleive it would be something like <?php if(mt_rand(1,100) == 50) { //Do w/e } ?> Quote
Faz` Posted July 27, 2009 Posted July 27, 2009 Re: How Would I do this? I have used mt_rand() before as well, however I did it differently to yours SkyFuse, but I think yours will work nonetheless. $blah = mt_rand(1,1000) if($blah == 14354) { //blah blah } Quote
Haunted Dawg Posted July 27, 2009 Posted July 27, 2009 Re: How Would I do this? They both the same. With SkyFuse's way you can not display the generated number. With your's you can. Quote
Guest Sniko` Posted July 31, 2009 Posted July 31, 2009 Re: How Would I do this? $blah = mt_rand(1,1000) if($blah == 14354) { //blah blah } As OPrime stated but you could add a bit of maths signs in there $blah = mt_rand(1,1000) if($blah < 500) { //less than 500 //blah blah } if($blah > 500) { //more than 500 //blah blah } Quote
POG1 Posted July 31, 2009 Posted July 31, 2009 Re: How Would I do this? $blah = mt_rand(1,1000) if($blah == 14354) { //blah blah } As OPrime stated but you could add a bit of maths signs in there $blah = mt_rand(1,1000) if($blah < 500) { //less than 500 //blah blah } if($blah > 500) { //more than 500 //blah blah } Your stuck if it is 500.. if($blah < 500) { //less than 500 } else { //more than 500 or = to 500 } Quote
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.