Random Numbers

closed account (LN7oGNh0)
When I was making this code, every time the program produces a random number, it is the same thing. I have already seeded the random number so that it makes a random number according to the current date and time. The problem is, I wan t the program to produce a new different number each time. So is using this: srand(static_cast<unsigned int>(time(0))); The only way? And if there is another way please tell me. Also, if this can be changed to make a new number each time the program produces a number?

Thank You.
Call srand only once at the start of main.
closed account (LN7oGNh0)
Do you mean before main()? Or after it?
Neither before, nor after. During.
closed account (LN7oGNh0)
OK thanks.
Example:
1
2
3
4
5
6
7
8
int main(){
	srand(time( NULL ));
	while ( 1 ){
	int loop = 1;
	A[loop] = (rand()%44);
	cout << A[loop] << endl;
	}
}
I'm sure we already did this.
http://www.cplusplus.com/forum/beginner/83980/
Topic archived. No new replies allowed.