C
Chelong
Hi All
I am using the srand function generate random numbers.Here is the
problem.
for example:
#include<iostream>
#include <time.h>
int main()
{
int i = 0,j = 0;
srand((int)time(0));
for(i=0; i<10; i++)
{
j=1+(int)(10.0*rand()/(RAND_MAX+1.0));
std::cout << j << '\t';
}
std::cout << std::endl;
return 0;
}
result£º
5 8 8 8 10 2 10 8 9 9
2 9 7 4 10 3 2 10 8 7
The problem is that the two lines of the result are the same when the
compiler run over in one seconds.
How the function works?
how the computer make the rand numbers?
Does the function can generate really Random Numbers ?
Please help me out if you find some solution for the above problem.
Thanks in advancs !
I am using the srand function generate random numbers.Here is the
problem.
for example:
#include<iostream>
#include <time.h>
int main()
{
int i = 0,j = 0;
srand((int)time(0));
for(i=0; i<10; i++)
{
j=1+(int)(10.0*rand()/(RAND_MAX+1.0));
std::cout << j << '\t';
}
std::cout << std::endl;
return 0;
}
result£º
5 8 8 8 10 2 10 8 9 9
2 9 7 4 10 3 2 10 8 7
The problem is that the two lines of the result are the same when the
compiler run over in one seconds.
How the function works?
how the computer make the rand numbers?
Does the function can generate really Random Numbers ?
Please help me out if you find some solution for the above problem.
Thanks in advancs !