How to create random with the exception?

How to set random from 1 to 6 with the exception of this period, for example, the number 3.
That is, the interval [1; 3) U (3;6], not including the three.
June 3rd 19 at 19:33
5 answers
June 3rd 19 at 19:35
Solution
for example:
function myRandom($min, $max, $exclude) {
 $random = random_int($min, $max);
 if( $random == $exclude) {
 return myRandom($min, $max, $exclude);
}
 else {
 return $random;
}
}
https://ideone.com/yXWAAp
June 3rd 19 at 19:37
Solution
generates from 1 to 5 and for values greater than 2 add 1
June 3rd 19 at 19:39
It is certainly possible to create an array.
$items = Array(1, 2, 4, 5, 6); //ruled out the top three
$twof = $items[array_rand($items)];


But I want to make everything easier, especially in his question, I greatly simplified the situation. Will have to do six of these arrays.
June 3rd 19 at 19:41
To fill an array with the desired values, i.e. 1, 2, 4, 5, 6. And randomized to generate the index of the element (from 0 to the length of the array).
Above himself introduced this option. But, unfortunately, it does not fit me - chanelle_Stamm51 commented on June 3rd 19 at 19:44
June 3rd 19 at 19:43
But I want to make everything easier, especially in his question, I greatly simplified the situation.

Write a function (feature set, class), which will obtain input from the range and exclude in a convenient syntax, and will parse this syntax, to form arrays and return what you want.

Find more questions by tags PHP