T
TreatmentPlant
I need to generate a few thousand true random numbers using C++.
I have some code now that does alright, but when you plot the results on
a graph, you notice patterns, so the numbers are not truly random, but
pseudo-random.
I tried randomly seeding the seed! to see if that improved things; it
didn't.
Can anyone help?
--8<-------------------------
float l_fMin=0.0;
float l_fMax=99.999;
int newSeed;
float num;
srand((unsigned)time(NULL));
for(int i=0;i<=2000;i++)
{
newSeed=rand();
srand((unsigned)newSeed);
num = ((float)rand() / (RAND_MAX+1)) * ((float)rand() / (RAND_MAX+1));
pfRandom = (float)((num * (l_fMax - l_fMin)) + l_fMin);
}
I have some code now that does alright, but when you plot the results on
a graph, you notice patterns, so the numbers are not truly random, but
pseudo-random.
I tried randomly seeding the seed! to see if that improved things; it
didn't.
Can anyone help?
--8<-------------------------
float l_fMin=0.0;
float l_fMax=99.999;
int newSeed;
float num;
srand((unsigned)time(NULL));
for(int i=0;i<=2000;i++)
{
newSeed=rand();
srand((unsigned)newSeed);
num = ((float)rand() / (RAND_MAX+1)) * ((float)rand() / (RAND_MAX+1));
pfRandom = (float)((num * (l_fMax - l_fMin)) + l_fMin);
}