Srand (Random Number Generator) Not Working!

Hello,

1
2
3
4
5
6
7
8
9
10
11
switch(userResponse)
	   {
	   
	    case 1: cout<< "Now, would not be a great time to admire the view! You're being attack by zombies!"<<endl;
		srand(time(0));
		int numpicked=  rand()% 15 + 1;
		healthlocation= healthlocation - numPicked;
		cout<< "A zombie attacks you whil you gaze around! Your health is now "<<healthlocation<<"%. Try to pick a better option next time."<<endl;
		}
	}
}


My srand in the code above will not generate random numbers! The "random number" will always end up as 100. Can anyone explain why this is happening!! It's not generating random numbers!

Thanks in advance.

Last edited on
Are you calling srand() every time you want a random number? If so, don't. Only call srand() once at the start of your program.
Thanks, It fixed my problem.
Topic archived. No new replies allowed.