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

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -