how do you use srand and time so you always get a diffrent variable to seed rand ?
i need to to know how to use srand and time together thank you
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;
}
|
thnaks :D
Topic archived. No new replies allowed.