Get random number that does/doesn't match criteria (PHP) -
Using PHP (in other languages, using the common built-in), how can I get random (or pseudo random)
IE: I need $ x = rand (0, 99)
, but only when ($ x% 9)! = 0
For example, while using a ()
loop and possibly when we have something that meets our criteria, then When using random numbers after loop?
while (($ rand_key = array_rand ($ array_of_items)) & amp; amp; ($ rand_key% 9 == 0)) {// nothing? }
or something like this:
while ($ rand_key = array_rand ($ array_of_items)) {if ($ rand_key% 9 == 0) {break ; }}
Or is there a more concise or reasonable way to accomplish this?
One of the rare cases, where a do-all loop actually helps
$ testData = array (7, 8, 9); {$ Rand = array_rand ($ testData); } While ($ testdata [$ rand]% 9 == 0); Echo $ testdata [$ rand];
Comments
Post a Comment