Here's how to do it:
int choices[2] = {2,3}; //choose between 2 and 3
// Seed the random generator with srand()
// Use rand() to pick either 0 or 1 and store in variable x
int L = choices[x];
Google for srand() and rand() to find out how they work, or read this
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
srand(time(NULL)); // put this at the beginning of your program
//do stuff
char choice[2] = {'a','b'};
char L = choice[rand()%2];
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
char AorB(char A, char B) { char T = rand%2 ? A : B ; return T; }
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
char AorB(char A, char B) { char T = rand%2 ? A : B ; return T; }
Or another step higher in obfuscation:
char AorB(char A, char B) { return (rand()%2 ? A : B); }
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403