Fred Bergman Fred Bergman - 2 months ago 8
PHP Question

Generate two numbers that are NOT equal in PHP

I need to generate two numbers that are NOT equal in PHP.

I know that I use

$random1 = (rand()%9);
to generate random a number between 0-9. I need to add something to this I guess.

Thanks!

Zed Zed
Answer
$rnd1 = rand(0,9);
do {
  $rnd2 = rand(0,9);
} while ($rnd1 == $rnd2);
Comments