Random Number Generator

I am trying to program an application that will generate a test of random preselected questions. I have each of 52 questions assigned a number, and I have it so it will pick a random number, if the number is 1 it will ask question 1, if it is 2 ect, however the random number generator does not seem to be working as I get the same questions each time. If anyone could tell me what I am doing wrong or how I could fix this problem it would be greatly appreciated.
...
if (distilledwater==0 and HCl==0 and NaOH==0)
{Randomquestion=rand()% 12 + 1; //Just Powder Questions
if (Randomquestion==1) {cout << "What color was the powder?\n";}
if (Randomquestion==2) {cout << "What was the shape and relative size of the particles of the powder?\n";}
if (Randomquestion==3) {cout << "Would you describe the structure of the powder as amorphic, uniform crystalline or irregular crystalline?\n";}
if (Randomquestion==4) {cout << "Did the substance have and odor, if so what was it like?\n";}
if (Randomquestion==5) {cout << "Describe the luster of the powder.\n";}
if (Randomquestion==6) {cout << "What was the density of the powder? \n";}...
You need to seed it first to get a real random effect.

srand(time(NULL));

Put that above your if statement and it should work.
Last edited on
Okay that worked and now the first question is random, how do I get the rest of the questions to be random.

If I put srand(time(NULL)); before them, they will always be the same a question one, but if I put srand (1); or other numbers in front of them, they will always be the same question as they were the last time.
Last edited on
Daubster meant that you should put that statement only above your first if statement.

Also, use [code][/code] tags for code ;)
Last edited on
Alright I fixed it an it works now. And sorry about the code thing, I will fix it next time.
Mark as solved, so others like me don't click it ;p
Topic archived. No new replies allowed.