Minimal Standard Random Numbers
[Random Numbers]

Collaboration diagram for Minimal Standard Random Numbers:

Data Structures

struct  bn_unif
struct  bn_gauss

Files

file  msr.c
 

Minimal Standard RANdom number generator.


Defines

#define BN_CK_UNIF(_p)   BU_CKMAG(_p, BN_UNIF_MAGIC, "bn_unif")
#define BN_CK_GAUSS(_p)   BU_CKMAG(_p, BN_GAUSS_MAGIC, "bn_gauss")
#define BN_UNIF_LONG(_p)
#define BN_UNIF_DOUBLE(_p)
#define BN_UNIF_CIRCLE(_p, _x, _y, _r)
#define BN_UNIF_SPHERE(_p, _x, _y, _z, _r)
#define BN_GAUSS_DOUBLE(_p)
#define BN_MSR_MAXTBL   4096
#define A   16807
#define M   2147483647
#define DM   2147483647.0
#define Q   127773
#define R   2836

Functions

struct bn_unifbn_unif_init (long setseed, int method)
void bn_unif_free (struct bn_unif *p)
long bn_unif_long_fill (struct bn_unif *p)
double bn_unif_double_fill (struct bn_unif *p)
struct bn_gaussbn_gauss_init (long setseed, int method)
void bn_gauss_free (struct bn_gauss *p)
double bn_gauss_fill (struct bn_gauss *p)
struct bn_unifbn_unif_init (long int setseed, int method)
struct bn_gaussbn_gauss_init (long int setseed, int method)

Detailed Description


Define Documentation

#define BN_CK_UNIF ( _p   )     BU_CKMAG(_p, BN_UNIF_MAGIC, "bn_unif")

Definition at line 706 of file bn.h.

Referenced by bn_unif_double_fill(), and bn_unif_long_fill().

#define BN_CK_GAUSS ( _p   )     BU_CKMAG(_p, BN_GAUSS_MAGIC, "bn_gauss")

Definition at line 707 of file bn.h.

Referenced by bn_gauss_fill().

#define BN_UNIF_LONG ( _p   ) 
Value:
(((_p)->msr_long_ptr) ? \
     (_p)->msr_longs[--(_p)->msr_long_ptr] : \
     bn_unif_long_fill(_p))

Definition at line 734 of file bn.h.

#define BN_UNIF_DOUBLE ( _p   ) 
Value:
(((_p)->msr_double_ptr) ? \
     (_p)->msr_doubles[--(_p)->msr_double_ptr] : \
     bn_unif_double_fill(_p))

Definition at line 738 of file bn.h.

#define BN_UNIF_CIRCLE ( _p,
_x,
_y,
_r   ) 
Value:
{ \
        do { \
            (_x) = 2.0*BN_UNIF_DOUBLE((_p)); \
            (_y) = 2.0*BN_UNIF_DOUBLE((_p)); \
            (_r) = (_x)*(_x)+(_y)*(_y); \
        } while ((_r) >= 1.0);  }

Definition at line 743 of file bn.h.

Referenced by bn_gauss_fill().

#define BN_UNIF_SPHERE ( _p,
_x,
_y,
_z,
_r   ) 
Value:
{ \
        do { \
            (_x) = 2.0*BN_UNIF_DOUBLE(_p); \
            (_y) = 2.0*BN_UNIF_DOUBLE(_p); \
            (_z) = 2.0*BN_UNIF_DOUBLE(_p); \
            (_r) = (_x)*(_x)+(_y)*(_y)+(_z)*(_z);\
        } while ((_r) >= 1.0) }

Definition at line 750 of file bn.h.

#define BN_GAUSS_DOUBLE ( _p   ) 
Value:
(((_p)->msr_gauss_ptr) ? \
     (_p)->msr_gausses[--(_p)->msr_gauss_ptr] : \
     bn_gauss_fill(_p))

Definition at line 758 of file bn.h.

#define BN_MSR_MAXTBL   4096

Note: BN_MSR_MAXTBL must be an even number, preferably a power of two. Size of random number tables.

Definition at line 45 of file msr.c.

Referenced by bn_gauss_fill(), bn_gauss_init(), bn_unif_double_fill(), bn_unif_init(), and bn_unif_long_fill().

#define A   16807
#define M   2147483647

Definition at line 74 of file msr.c.

Referenced by bn_mat_fromto(), bn_randmt_state(), bn_unif_double_fill(), and bn_unif_long_fill().

#define DM   2147483647.0

Definition at line 75 of file msr.c.

Referenced by bn_unif_double_fill().

#define Q   127773

Q = M / A

Definition at line 76 of file msr.c.

Referenced by bn_mat_fromto(), bn_unif_double_fill(), and bn_unif_long_fill().

#define R   2836

R = M % A

Definition at line 77 of file msr.c.

Referenced by bn_mat_fromto(), bn_unif_double_fill(), and bn_unif_long_fill().


Function Documentation

struct bn_unif* bn_unif_init ( long  setseed,
int  method 
) [read]
void bn_unif_free ( struct bn_unif p  ) 

Definition at line 226 of file msr.c.

References bn_unif::magic, bn_unif::msr_doubles, and bn_unif::msr_longs.

long bn_unif_long_fill ( struct bn_unif p  ) 

bn_unif_long_fill fill a random number table.

Use the msrad algorithm to fill a random number table with values from 1 to 2^31-1. These numbers can (and are) extracted from the random number table via high speed macros and bn_unif_long_fill called when the table is exauseted.

Entry
p pointer to a bn_unif structure.
Exit
if (!p) returns 1 else returns a value between 1 and 2^31-1
Calls
None. msran is inlined for speed reasons.
Uses
None.
Method
if (!p) return 1; if p->msr_longs != NULL msr_longs is reloaded with random numbers; msr_long_ptr is set to BN_MSR_MAXTBL endif msr_seed is updated.

Definition at line 126 of file msr.c.

References A, BN_CK_UNIF, BN_MSR_MAXTBL, M, bn_unif::magic, bn_unif::msr_long_ptr, bn_unif::msr_longs, bn_unif::msr_seed, Q, and R.

double bn_unif_double_fill ( struct bn_unif p  ) 

bn_unif_double_fill fill a random number table.

Use the msrad algorithm to fill a random number table with values from -0.5 to 0.5. These numbers can (and are) extracted from the random number table via high speed macros and bn_unif_double_fill called when the table is exauseted.

Entry
p pointer to a bn_unif structure.
Exit
if (!p) returns 0.0 else returns a value between -0.5 and 0.5
Calls
None. msran is inlined for speed reasons.
Uses
None.
Method
if (!p) return (0.0) if p->msr_longs != NULL msr_longs is reloaded with random numbers; msr_long_ptr is set to BN_MSR_MAXTBL endif msr_seed is updated.

Definition at line 188 of file msr.c.

References A, BN_CK_UNIF, BN_MSR_MAXTBL, DM, M, bn_unif::magic, bn_unif::msr_double_ptr, bn_unif::msr_doubles, bn_unif::msr_seed, Q, and R.

struct bn_gauss* bn_gauss_init ( long  setseed,
int  method 
) [read]
void bn_gauss_free ( struct bn_gauss p  ) 

Definition at line 339 of file msr.c.

References bn_gauss::msr_gauss_doubles, and bn_gauss::msr_gausses.

double bn_gauss_fill ( struct bn_gauss p  ) 
struct bn_unif* bn_unif_init ( long int  setseed,
int  method 
) [read]
struct bn_gauss* bn_gauss_init ( long int  setseed,
int  method 
) [read]
Generated on Tue Dec 11 13:14:29 2012 for LIBBN by  doxygen 1.6.3