Selecting one of two random numbers.

I need to select one of two random numbers in my program. I was originally going to put the two values in an array and srand to pick one, but as I'm only using two, I was wondering if there's a more efficient way of doing this.

Any hints/tips would be greatly appreciated.

Cheers,
S
Just wondering why this would ever be useful. If they are both random numbers, why not just generate one?
Sorry. What I meant is I need to pick one of two numbers at random.
Get a new random number and if it is even, use the firt number; if it is odd, use the second number:
1
2
3
4
int n1, n2, r;
r=rand();
if (r%2==0) // use n1;
else //use n2 
Last edited on
Cheers, Baz. I'll give it a shot.
Topic archived. No new replies allowed.