how do you use srand and time so you always get a diffrent variable to seed rand ?
May 25, 2011 at 8:31pm
i need to to know how to use srand and time together thank you
May 25, 2011 at 8:35pm
1) call srand once and only once when your program starts
2) call rand as many times as needed after that. Each call gives a different random number.
1 2 3 4 5 6 7 8 9
|
int main()
{
// seed it once:
srand(time(0));
// a bunch of random numbers:
for(int i = 0; i < 10; ++i)
cout << rand() << endl;
}
|
May 25, 2011 at 9:00pm
thnaks :D
Topic archived. No new replies allowed.