Hi,
I was wondering how to get the computer to randomly select between 0, 1, or 2.
instead of taking the MOD of 100 take the MOD of 2 that should get you 0,1,2. I'm to lazy to run it, but if it just gets you 1 and 2. then do the mod of 3 and take 1 from it. ie
(rand() % 3) - 1.
in c++ you have to seed the random function, (give it a number to generate a random from) people generally use system time, so they get more random results.
printf ("First number: %d\n", rand() % 2);
srand ( time(NULL) );
printf ("Random number: %d\n", rand() % 2);
srand ( 1 );
printf ("Again the first number: %d\n", rand() % 2)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.