-
how
how would u get different numbers in the 2 loops?
code:
#include <stdlib.h>
#include <time.h>
#include <iostream.h>
int funk1()
{
srand((unsigned)time(NULL));
int d=rand()%7;
cout<<d<<flush;
return 0;
}
int funk2()
{
srand((unsigned)time(NULL));
int d=rand()%7;
cout<<d<<flush;
return 0;
}
main()
{
funk1();
cout<<"--";
funk2();
return 0;
}
-
-
like this....
Code:
#include <stdlib.h>
#include <time.h>
#include <iostream.h>
int funk1()
{
int d=rand()%7;
cout<<d<<flush;
return 0;
}
int funk2()
{
int d=rand()%7;
cout<<d<<flush;
return 0;
}
int main()
{
srand((unsigned)time(NULL));
funk1();
cout<<"--";
funk2();
return 0;
}
-
You don't want to call srand more than once (especially if you're using the time as the argument).
rand() will be seeded with the value entered into srand(), this is the value that it will use to begin producing pseudo random numbers. If you use the time to seed your random number generator, and then re-seed before time has advanced, you're restarting the number series produced by rand() with the same seed and will therefore get the same result.
-