1

I'm generating a random number within 1 to 15 using the following code.

<?php
$except = '4';
$rand = rand(1,15);
echo $rand;
?>

But if the random number generated is 4, I want to print any other random number except 4.

1 Answer 1

4

If you use a condition loop like this, you will get random numbers except 4:

<?php
$except = 4;

do {
    $rand = rand(1,15);
} while ($rand == $except);

echo $rand;
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.