I need to get a random number that is between
0 - 80
and
120 - 200
I can do
$n1 = rand(0, 80);
$n2 = rand(120, 200);
But then I need to choose between n1 and n2. Cannot do
$n3 = rand($n1, $n2)
as this may give me a number between 80 - 120 which I need to avoid.
How to solve this?
Since both ranges have different sizes (even if only by 1 number), to ensure good random spread, you need to do this:
Fastest method. 🙂
The way this works is by pretending it’s a single range, and if it ends up picking a number above the first range, we increase it to fit within the second range. This ensures perfect spread.