I have an integer 'a'. It is a random number from 1-10. How do I express interger 'b' to be a random number from 1-10, but not equal to 'a'?
Would it be something like this?:

srand ( time(NULL) );
a = rand() % 10 + 1;
b = rand() % 10 + 1, != a;

You can try using a do...while loop and do b = rand() % 10 + 1 while b equals a.

try something like this :

const int UPPER_LIMIT = 10;
const int LOWER_LIMIT = 0;
int chosenOne = 3; //within lower and upper limit
int  random = chosenOne;
while(chosenOne == random){
 random = randomNumber(LOWER_LIMIT,UPPER_LIMIT);
}

I'll let you define randomNumber(int,int) function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.