C
ChasW
given the following example:
Using gcc, this compiles, runs, and outputs as expected, but on
vc++.net 2003, the first number is always the same despite the time
seed.
#include <ctime>
#include <iostream>
using namespace std;
// output 10 numbers ranging from [0, n)
int main ()
{
srand((unsigned int)time(NULL));
int n = 100;
for (int i = 0; i < 10; ++i)
{
cout << int(double(rand()) * n / (RAND_MAX + 1.0)) << "\n";
}
cout << endl;
return 0;
}
What am i doing wrong?
Charles
Using gcc, this compiles, runs, and outputs as expected, but on
vc++.net 2003, the first number is always the same despite the time
seed.
#include <ctime>
#include <iostream>
using namespace std;
// output 10 numbers ranging from [0, n)
int main ()
{
srand((unsigned int)time(NULL));
int n = 100;
for (int i = 0; i < 10; ++i)
{
cout << int(double(rand()) * n / (RAND_MAX + 1.0)) << "\n";
}
cout << endl;
return 0;
}
What am i doing wrong?
Charles