LibRan  0.1
Pseudo-random number distribution generator
Macros | Functions | Variables
urand.c File Reference

Specialized sequential congruential uniform pseudo-random number generator. More...

#include "config.h"
#include "libran.h"
#include <string.h>
Include dependency graph for urand.c:

Go to the source code of this file.

Macros

#define SQRT3   1.7320508075688772935
 
#define PI   3.141592653589793238462643
 

Functions

void _set_rand (void)
 
int LR_irand (LR_obj *o)
 LR_irand(LR_obj *) - returns int in range [0,LR_IRAND_IMAX]. More...
 
float LR_frand (LR_obj *o)
 LR_frand(LR_obj *) - returns float in range [0.0,1.0) More...
 
void LR_isetseed (LR_obj *o, int X)
 LR_isetseed(LR_obj *, int X) - set the seed to X. More...
 
int LR_igetseed (LR_obj *o)
 LR_igetseed(LR_obj *) - get the current seed. More...
 
int LR_igetrand (LR_obj *o)
 LR_igetrand(LR_obj *) - get the current pseudo-random number. More...
 
float LR_fgetrand (LR_obj *o)
 LR_fgetrand(LR_obj *) - get the current pseudo-random number. More...
 
long LR_lrand (LR_obj *o)
 LR_lrand(LR_obj *) - returns long in range [0,LR_IRAND_LMAX]. More...
 
double LR_drand (LR_obj *o)
 LR_drand(LR_obj *) - returns double in range [0.0,1.0) More...
 
void LR_lsetseed (LR_obj *o, long X)
 LR_lsetseed(LR_obj *, long X) - set the seed to X. More...
 
long LR_lgetseed (LR_obj *o)
 LR_lgetseed(LR_obj *) - get the current seed. More...
 
long LR_lgetrand (LR_obj *o)
 LR_lgetrand(LR_obj *) - get the current pseudo-random number. More...
 
double LR_dgetrand (LR_obj *o)
 LR_dgetrand(LR_obj *) - get the current pseudo-random number. More...
 
int LR_igetval (char *val)
 LR_igetval(char *val) - return the configure value. More...
 
long LR_lgetval (char *val)
 LR_lgetval(char *val) - return the configure value. More...
 
float LR_fgetval (char *val)
 LR_fgetval(char *val) - return the configure value. More...
 
double LR_dgetval (char *val)
 LR_dgetval(char *val) - return the configure value. More...
 

Variables

float lr_fscale
 
float lr_fhalfm
 
double lr_dscale
 
double lr_dhalfm
 
int lr_ia = 0
 
int lr_ic = 0
 
int lr_imc = 0
 
long lr_la = 0
 
long lr_lc = 0
 
long lr_lmc = 0
 

Detailed Description

Specialized sequential congruential uniform pseudo-random number generator.

Urand is a specialized sequential congruential uniform pseudo-random number generator based on theory and suggestions given in D.E. Knuth (1969), vol 2. and then republished by G.E. Forsysth, M.A. Malcolm, and C.B. Moler (1977); and converted from Fortran 77 to C with f2c.

Modified to fit into the LibRan package, and to isolate each pseudo-random sequence to each LibRan object.

This routine is highly optimized by the configuration step to provide the fastest set of operations for computing the next value in the sequence. However, this does not lend itself to cross compiling, since the configuration step requires testing on the actual intended hardware and environment.

The LR_*rand routine should generally not be called directly ... call the LR_obj object with the unif distribution instead as follows.

#include "libran.h"
...
LR_obj *o = LR_new(unif, LR_double);
// set the seed
LR_lsetseed(19580512L);
...
// generate random number
x = LR_RAN(o);
// get the same random number
y = LR_lgetrand(o);
...
// remove object
LR_rm(&o);
...

These routines are specific to this internal LibRan sequential congruential uniform pseudo-random generator. If a different pseudo-random generator is used then these are probably no longer effective.

Definition in file urand.c.

Function Documentation

◆ LR_dgetrand()

double LR_dgetrand ( LR_obj o)

LR_dgetrand(LR_obj *) - get the current pseudo-random number.

Get the current pseudo-random number from this LR_obj .

Parameters
oLR_obj object
Returns
double current pseudo-random number

Definition at line 405 of file urand.c.

◆ LR_dgetval()

double LR_dgetval ( char *  val)

LR_dgetval(char *val) - return the configure value.

Return the value computed from the library configuration step, such as LR_DEPS , and LR_DSQEPS .

See also
urand/config.h
Parameters
valconfiguration parameter
Returns
double configuration value

Definition at line 483 of file urand.c.

◆ LR_drand()

double LR_drand ( LR_obj o)

LR_drand(LR_obj *) - returns double in range [0.0,1.0)

Returns a pseudo-random double in the range [0.0, 1.0)

Parameters
oLR_obj object
Returns
double range [0.0, 1.0)

Definition at line 342 of file urand.c.

◆ LR_fgetrand()

float LR_fgetrand ( LR_obj o)

LR_fgetrand(LR_obj *) - get the current pseudo-random number.

Get the current pseudo-random number from this LR_obj .

Parameters
oLR_obj object
Returns
float current pseudo-random number

Definition at line 256 of file urand.c.

◆ LR_fgetval()

float LR_fgetval ( char *  val)

LR_fgetval(char *val) - return the configure value.

Return the value computed from the library configuration step, such as LR_FEPS , and LR_FSQEPS .

See also
urand/config.h
Parameters
valconfiguration parameter
Returns
float configuration value

Definition at line 464 of file urand.c.

◆ LR_frand()

float LR_frand ( LR_obj o)

LR_frand(LR_obj *) - returns float in range [0.0,1.0)

Returns a pseudo-random float in the range [0.0, 1.0)

Parameters
oLR_obj object
Returns
float range [0.0, 1.0)

Definition at line 193 of file urand.c.

◆ LR_igetrand()

int LR_igetrand ( LR_obj o)

LR_igetrand(LR_obj *) - get the current pseudo-random number.

Get the current pseudo-random number from this LR_obj .

Parameters
oLR_obj object
Returns
int current pseudo-random number

Definition at line 243 of file urand.c.

◆ LR_igetseed()

int LR_igetseed ( LR_obj o)

LR_igetseed(LR_obj *) - get the current seed.

Get the seed from this LR_obj .

Parameters
oLR_obj object
Returns
int current object seed

Definition at line 230 of file urand.c.

◆ LR_igetval()

int LR_igetval ( char *  val)

LR_igetval(char *val) - return the configure value.

Return the value computed from the library configuration step, such as LR_IRAND_IMAX2 , LR_IRAND_IMAX , and LR_IRAND_INOT .

See also
urand/config.h
Parameters
valconfiguration parameter
Returns
int configuration value

Definition at line 422 of file urand.c.

◆ LR_irand()

int LR_irand ( LR_obj o)

LR_irand(LR_obj *) - returns int in range [0,LR_IRAND_IMAX].

Returns a pseudo-random int in the range [0,LR_IRAND_MAX]

Parameters
oLR_obj object
Returns
int range [0, LR_IRAND_IMAX]

Definition at line 121 of file urand.c.

◆ LR_isetseed()

void LR_isetseed ( LR_obj o,
int  X 
)

LR_isetseed(LR_obj *, int X) - set the seed to X.

Set the seed for this LR_obj .

Parameters
oLR_obj object
Xint with new seed
Returns
void

Definition at line 212 of file urand.c.

◆ LR_lgetrand()

long LR_lgetrand ( LR_obj o)

LR_lgetrand(LR_obj *) - get the current pseudo-random number.

Get the current pseudo-random number from this LR_obj .

Parameters
oLR_obj object
Returns
long current pseudo-random number

Definition at line 392 of file urand.c.

◆ LR_lgetseed()

long LR_lgetseed ( LR_obj o)

LR_lgetseed(LR_obj *) - get the current seed.

Get the seed from this LR_obj .

Parameters
oLR_obj object
Returns
long current object seed

Definition at line 379 of file urand.c.

◆ LR_lgetval()

long LR_lgetval ( char *  val)

LR_lgetval(char *val) - return the configure value.

Return the value computed from the library configuration step, such as LR_IRAND_LMAX2 , LR_IRAND_LMAX , and LR_IRAND_LNOT .

See also
urand/config.h
Parameters
valconfiguration parameter
Returns
long configuration value

Definition at line 443 of file urand.c.

◆ LR_lrand()

long LR_lrand ( LR_obj o)

LR_lrand(LR_obj *) - returns long in range [0,LR_IRAND_LMAX].

Returns a pseudo-random int in the range [0,LR_IRAND_LMAX]

Parameters
oLR_obj object
Returns
int range [0, LR_IRAND_LMAX]

Definition at line 270 of file urand.c.

◆ LR_lsetseed()

void LR_lsetseed ( LR_obj o,
long  X 
)

LR_lsetseed(LR_obj *, long X) - set the seed to X.

Set the seed for this LR_obj .

Parameters
oLR_obj object
Xlong with new seed
Returns
void

Definition at line 361 of file urand.c.