There is no built-in function, but you can do this:
function randWithout($from, $to, array $exceptions) {
sort($exceptions);
$number = rand($from, $to - count($exceptions));
foreach ($exceptions as $exception) {
if ($number >= $exception) {
$number++;
} else {
break;
}
}
return $number;
}
This is from my mind, so it can use polishing - but at least you cannot end up with an endless loop script, even hypothetically.
: , $exceptions - . randWithout(1, 2, array(1,2)) randWithout(1, 2, array(0,1,2,3)) (), $from - $to, .
$exceptions , sort($exceptions); .
Eye-candy: .