5#include "tpcclibConfig.h"
32#if defined HAVE_TIMESPEC_GET
34 timespec_get(&ts, TIME_UTC);
36 li=((ts.tv_sec % 10000)*523 ^ ts.tv_nsec*10) ^ ((getpid() % 1000)*983);
37#elif defined HAVE_CLOCK_GETTIME
39 clock_gettime(CLOCK_REALTIME, &ts);
41 li=((ts.tv_sec % 10000)*523 ^ ts.tv_nsec*10) ^ ((getpid() % 1000)*983);
42#elif defined HAVE_GETTIMEOFDAY
45 li=((tv.tv_sec % 10000)*523 ^ tv.tv_usec*13) ^ ((getpid() % 1000)*983);
47 li=(
unsigned int)time(NULL)+(
unsigned int)getpid();
49 li+=(
unsigned int)rand();
71 d = ( ( s*rand() + rand() )*s + rand() ) * s;
103 double dif, v, stl, stu;
106 if(d==NULL || type<0 || type>1)
return 1;
108 dif=up-low;
if(dif<0.0)
return 2;
110 for(i=0; i<nr; i++) d[i]=low;
115 for(i=0; i<nr; i++) d[i] =
drand()*dif + low;
117 stl=copysign(sqrt(fabs(low)),low);
if(!isnormal(stl)) stl=0.0;
118 stu=copysign(sqrt(fabs(up)), up);
if(!isnormal(stu)) stu=0.0;
120 for(i=0; i<nr; i++) {v=
drand()*dif+stl; d[i]=copysign(v*v, v);}
148 double fac, rsq, a, b;
153 a = 2.*
drand() - 1.0;
154 b = 2.*
drand() - 1.0;
156 }
while (rsq>1.0 || rsq==0.0);
158 fac = sqrt(-2.0*log(rsq)/rsq);
186 return(-mean*log(r));
int drandRange(unsigned int nr, double *d, double low, double up, int type)
double drandExponential(double mean)
Get pseudo-random number with exponential distribution.
double drandGaussian()
Get pseudo-random number with normal (Gaussian) distribution with mean 0 and SD 1.
unsigned int drandSeed(short int seed)
Make and optionally set the seed for rand(), drand, drandRange, and drandGaussian().
Header file for library libtpcextensions.
Header file for libtpcrand.