1 static const char AUTHOR[]=
"@(#)urand 06/02/94 1.3 R.K.Owen,PhD";
2 static const char RCSID[]=
"$Id: urand.c 106 2002-02-10 08:02:39Z rk $";
83 float lr_fscale, lr_fhalfm;
84 double lr_dscale, lr_dhalfm;
85 int lr_ia = 0, lr_ic = 0, lr_imc = 0;
86 long lr_la = 0, lr_lc = 0, lr_lmc = 0;
88 #define SQRT3 1.7320508075688772935 89 #define PI 3.141592653589793238462643 91 void _set_rand(
void) {
92 extern float lr_fscale, lr_fhalfm;
93 extern double lr_dscale, lr_dhalfm;
94 extern int lr_ia, lr_ic, lr_imc;
95 extern long lr_la, lr_lc, lr_lmc;
101 lr_ia = ((int) (lr_fhalfm * PI / 32.) << 3) + 5;
102 lr_ic = ((int) (lr_fhalfm * (.5 - SQRT3 / 6.)) << 1) + 1;
104 lr_la = ((long) (lr_dhalfm * PI / 32.) << 3) + 5;
105 lr_lc = ((long) (lr_dhalfm * (.5 - SQRT3 / 6.)) << 1) + 1;
109 lr_fscale = .5 / lr_fhalfm;
110 lr_dscale = .5 / lr_dhalfm;
123 extern float lr_fscale, lr_fhalfm;
124 extern int lr_ia, lr_ic, lr_imc;
127 if (lr_ia == 0) _set_rand();
134 if (o->
iy.
i > lr_imc) {
138 #elif defined LR_NOISUB 141 # error "Need either LR_ISUB or LR_NOISUB to be defined" 153 # elif defined LR_NOIDIV
156 # error
"Need either LR_IDIV or LR_NOIDIV to be defined" 162 # elif defined LR_NOISUB 165 # error "Need either LR_ISUB or LR_NOISUB to be defined" 176 #elif defined LR_NOIADD 179 # error "Need either LR_IADD or LR_NOIADD to be defined" 195 extern float lr_fscale;
200 return (
float) (o->
iy.
i) * lr_fscale;
217 if (lr_ia == 0) _set_rand();
258 extern float lr_fscale;
259 return (
float) (o->
iy.
i) * lr_fscale;
272 extern double lr_dscale, lr_dhalfm;
273 extern long lr_la, lr_lc, lr_lmc;
276 if (lr_la == 0) _set_rand();
283 if (o->
iy.
l > lr_lmc) {
287 #elif defined LR_NOISUB 290 # error "Need either LR_ISUB or LR_NOISUB to be defined" 302 #elif defined LR_NOIDIV
305 # error
"Need either LR_IDIV or LR_NOIDIV to be defined" 311 #elif defined LR_NOISUB 314 # error "Need either LR_ISUB or LR_NOISUB to be defined" 325 #elif defined LR_NOLADD 328 # error "Need either LR_LADD or LR_NOIADD to be defined" 344 extern double lr_dscale;
349 return (
double) (o->
iy.
l) * lr_dscale;
366 if (lr_la == 0) _set_rand();
407 extern double lr_dscale;
408 return (
double) (o->
iy.
l) * lr_dscale;
423 if (!strcmp(val,
"LR_IRAND_IMAX2"))
425 else if (!strcmp(val,
"LR_IRAND_IMAX"))
427 else if (!strcmp(val,
"LR_IRAND_INOT"))
444 if (!strcmp(val,
"LR_IRAND_LMAX2"))
446 else if (!strcmp(val,
"LR_IRAND_LMAX"))
448 else if (!strcmp(val,
"LR_IRAND_LNOT"))
465 if (!strcmp(val,
"LR_FEPS"))
467 else if (!strcmp(val,
"LR_FSQEPS"))
484 if (!strcmp(val,
"LR_DEPS"))
486 else if (!strcmp(val,
"LR_DSQEPS"))
double LR_dgetval(char *val)
LR_dgetval(char *val) - return the configure value.
float LR_fgetrand(LR_obj *o)
LR_fgetrand(LR_obj *) - get the current pseudo-random number.
long LR_lgetval(char *val)
LR_lgetval(char *val) - return the configure value.
long LR_lgetseed(LR_obj *o)
LR_lgetseed(LR_obj *) - get the current seed.
#define LR_IRAND_LMAX
LibRan IRAND max long value.
double LR_drand(LR_obj *o)
LR_drand(LR_obj *) - returns double in range [0.0,1.0)
long LR_lgetrand(LR_obj *o)
LR_lgetrand(LR_obj *) - get the current pseudo-random number.
float LR_frand(LR_obj *o)
LR_frand(LR_obj *) - returns float in range [0.0,1.0)
#define LR_IRAND_LNOT
LibRan IRAND long NOT max (in hex)
#define LR_IRAND_IMAX2
LibRan IRAND half max int value.
#define LR_IRAND_INOT
LibRan IRAND int NOT max (in hex)
double LR_dgetrand(LR_obj *o)
LR_dgetrand(LR_obj *) - get the current pseudo-random number.
int LR_igetseed(LR_obj *o)
LR_igetseed(LR_obj *) - get the current seed.
#define LR_FEPS
LibRan float machine epsilon.
int LR_igetrand(LR_obj *o)
LR_igetrand(LR_obj *) - get the current pseudo-random number.
#define LR_IRAND_IMAX
LibRan IRAND max int value.
#define LR_FSQEPS
LibRan float sqrt machine epsilon.
void LR_lsetseed(LR_obj *o, long X)
LR_lsetseed(LR_obj *, long X) - set the seed to X.
int LR_igetval(char *val)
LR_igetval(char *val) - return the configure value.
int LR_irand(LR_obj *o)
LR_irand(LR_obj *) - returns int in range [0,LR_IRAND_IMAX].
Generated by the configuration step.
#define LR_DSQEPS
LibRan double sqrt machine epsilon.
#define LR_DEPS
LibRan double machine epsilon.
float LR_fgetval(char *val)
LR_fgetval(char *val) - return the configure value.
The LibRan common header file.
long LR_lrand(LR_obj *o)
LR_lrand(LR_obj *) - returns long in range [0,LR_IRAND_LMAX].
void LR_isetseed(LR_obj *o, int X)
LR_isetseed(LR_obj *, int X) - set the seed to X.
the fundamental LibRan random variate distribution object
#define LR_IRAND_LMAX2
LibRan IRAND half max long value.