470,810 Members | 1,444 Online

# Random Numbers 16
I know that you can scale random numbers down to a range that you want. For instance I know that I can generate a random number between [m,n] inclusive.
What I want to do is generate a random number between [m,n], BUT I want to exclude certain numbers in this range. For example let's say that I wanted to generate a random number between 4 and 10,but I want to exclude 6 and 8. How could I do that? Is it just as simple as something like this:

rand() !=6 && !=8;

I know that the above code is not correct,but am I on the right track?
Oct 24 '08 #1
2 1847 JosAH
11,448 Expert 8TB
Yep, you're on the right track. Simply generate another pseudo random number
if it hit one of the 'forbidden' numbers.

kind regards,

Jos
Oct 24 '08 #2
curiously enough
79 I know that you can scale random numbers down to a range that you want. For instance I know that I can generate a random number between [m,n] inclusive.
What I want to do is generate a random number between [m,n], BUT I want to exclude certain numbers in this range. For example let's say that I wanted to generate a random number between 4 and 10,but I want to exclude 6 and 8. How could I do that? Is it just as simple as something like this:

rand() !=6 && !=8;

I know that the above code is not correct,but am I on the right track?
Yes you are. You can just exclude 6 and 8 with a do while loop.
Oct 24 '08 #3