tests
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -79,7 +79,7 @@ namespace random
|
||||
// CPU-specific code (host path)
|
||||
if(state==NULL) state = &global_rand_cpustate;
|
||||
#endif
|
||||
ret= ((float)randui32(state))/(2147483648.0f);
|
||||
ret= ((float)randui32(state))/(4294967296.0f);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ namespace random
|
||||
// CPU-specific code (host path)
|
||||
if(state==NULL) state = &global_rand_cpustate;
|
||||
#endif
|
||||
ret= ((double)randui32(state))/(2147483648.0f);
|
||||
ret= ((double)randui32(state))/(4294967296.0f);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -9,9 +9,70 @@ namespace random
|
||||
{
|
||||
using namespace random;
|
||||
printf("Random number generator basic function test:\n");
|
||||
|
||||
int I;
|
||||
// uint32_t q1;
|
||||
// float q2;
|
||||
// double q3;
|
||||
// int q4;
|
||||
|
||||
rand_seed(0);
|
||||
printf("from seed 0...\n");
|
||||
for(I=0;I<10;I++)
|
||||
{
|
||||
printf("randui32[%d] = %u\n",I,randui32());
|
||||
}
|
||||
|
||||
rand_seed(0);
|
||||
printf("from seed 0...\n");
|
||||
for(I=0;I<10;I++)
|
||||
{
|
||||
printf("randf[%d] = %1.3f\n",I,randf());
|
||||
}
|
||||
|
||||
rand_seed(0);
|
||||
printf("from seed 0...\n");
|
||||
for(I=0;I<10;I++)
|
||||
{
|
||||
printf("randf[%d] = %1.3f\n",I,rand());
|
||||
}
|
||||
|
||||
float q0,qlast,qmindelta,qmaxdelta,qmx,qmn,qmean,qstd,qsum,qsumsq;
|
||||
int N = 100000;
|
||||
uint32_t seed= 34533623;
|
||||
rand_seed(seed);
|
||||
printf("from seed %u...\n",seed);
|
||||
q0 = randf();
|
||||
qmx = q0;
|
||||
qmn = q0;
|
||||
qsum = 0.0f;
|
||||
qsumsq = 0.0f;
|
||||
qlast = q0;
|
||||
q0 = randf();
|
||||
qmindelta = ::fabsf(q0-qlast);
|
||||
qmaxdelta = ::fabsf(q0-qlast);
|
||||
for(I=0;I<N;I++)
|
||||
{
|
||||
qlast = q0;
|
||||
q0 = randf();
|
||||
|
||||
qsum += q0;
|
||||
qsumsq += q0*q0;
|
||||
if(q0>qmx) qmx = q0;
|
||||
if(q0<qmn) qmn = q0;
|
||||
if(::fabsf(q0-qlast)<qmindelta) qmindelta = ::fabsf(q0-qlast);
|
||||
if(::fabsf(q0-qlast)>qmaxdelta) qmaxdelta = ::fabsf(q0-qlast);
|
||||
}
|
||||
|
||||
qmean = qsum/((float)N);
|
||||
qstd = ::sqrtf((qsumsq-qsum*qsum/((float)N))/((float)N));
|
||||
|
||||
printf("Statistics for randf() N=%d\n",N);
|
||||
printf("\tmin: %1.3g\n",qmn);
|
||||
printf("\tmax: %1.3g\n",qmx);
|
||||
printf("\tmean: %1.3g\n",qmean);
|
||||
printf("\tstdev: %1.3g\n",qstd);
|
||||
printf("\tmindelta: %1.3g\n",qmindelta);
|
||||
printf("\tmaxdelta: %1.3g\n",qmaxdelta);
|
||||
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user