Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ addrans(3M) — Sun C 1.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

drand48(3)

lcrans(3M)

rand(3C)

rand(3V)

random(3)

shufrans(3M)

ADDRANS(3M)  —  MATHEMATICAL LIBRARY

NAME

addrans − additive pseudo-random number generators

SYNOPSIS

#include <math.h>
 #define ADDRAN_SIZE 55
 int i_addran_()
double d_addran_()
FLOATFUNCTIONTYPE r_addran_()
 void i_addrans_(x,n,l,u)
int ∗x, ∗l, ∗u;
int ∗n;
 void u_addrans_(x,n,l,u)
unsigned ∗x, ∗l, ∗u;
int ∗n;
 void d_addrans_(x,n,l,u)
double ∗x, ∗l, ∗u;
int ∗n;
 void r_addrans_(x,n,l,u)
float ∗x, ∗l, ∗u;
int ∗n;
 void i_get_addrans_(x)
int ∗x ;
 void i_set_addrans_(x)
int ∗x ;
 void r_get_addrans_(x)
float ∗x ;
 void r_set_addrans_(x)
float ∗x ;
 void d_get_addrans_(x)
double ∗x ;
 void d_set_addrans_(x)
double ∗x ;
 void i_init_addrans_()
void r_init_addrans_()
void d_init_addrans_()
 

 

DESCRIPTION

These functions provide uniform random variates, of types integer or unsigned, single-precision floating-point, or double-precision floating-point. 

Additive variates are generated one at a time by ..._addran_() using the recurrence

 addran_last = addran_table[i] - addran_table[(i-24) % ADDRAN_SIZE] ;
addran_table[i] = addran_last;
i = (i+1) % ADDRAN_SIZE ;
return addran_last;
 

addran_table is a table containing ADDRAN_SIZE elements of type unsigned, float, or double.  The variates are constrained to the following intervals:
 

type lower bound upper bound
name value name value
unsigned U_ADDRAN_LB 0 U_ADDRAN_UB 4294967295
integer I_ADDRAN_LB −2147483648 I_ADDRAN_UB 2147483647
float R_ADDRAN_LB 0 R_ADDRAN_UB 0.9999999403953552246
double D_ADDRAN_LB 0 D_ADDRAN_UB 0.9999999999999998890

 
by adding, when necessary, 4294967296 for integer and unsigned, and 1.0 for float and double. Thus any representable 32-bit integer or unsigned is an equally likely result from i_addran_() or u_addran_(); furthermore it hardly matters that "additive" methods are implemented by subtraction for efficiency.

Additive variates are generated ∗n at a time by ..._addrans_() using the recurrence

 addran_last = addran_table_[i] - addran_table_[(i-24) % ADDRAN_SIZE] ;
addran_table[i] = addran_last;
i = (i+1) % ADDRAN_SIZE ;
return scale ∗ (addran_last + offset)
 

where scale and offset are calculated from ∗l and ∗u so that the computed variates are uniform in [∗l,∗u].  u_addrans_() is available so that large unsigned bounds can be specified.  u_addrans_() uses the same addran_table as i_addrans_(). 

The state of the additive generator, an array of ADDRAN_SIZE, may be obtained with ...get_addrans_() and set with ...set_addrans_(), or restored to the initial state with ...init_addrans_(). 

EXAMPLES

to generate 1000 double-precision random variates in [0,1)

double x[1000] ; int n = 1000 ; double lb = D_ADDRAN_LB, ub = D_ADDRAN_UB ;
 for ( ; n > 0 ; n--) ∗x+ = d_addran_(); /∗ or... ∗/
d_addrans_(x, &n, &lb, &ub) ;/∗ same output, but more efficient ∗/

to generate 1000 integer random variates in [-10,+10]

int x[1000] ; int n = 1000, lb = −10, ub = −10 ;
 
i_addrans_(x, &n, &lb, &ub) ;

FILES

/usr/include/math.h
function declarations

/usr/lib/libm.a function archive

SEE ALSO

drand48(3), lcrans(3M), rand(3C), rand(3V), random(3), shufrans(3M). 

Knuth, Seminumerical Algorithms, 1981, Addison-Wesley. 

Park and Miller, Random Number Generators: Good Ones are Hard to Find, Communications of the ACM, October 1988. 

NOTES

The functions in addrans(3M) are generally more efficient but their theory is not as refined as those in lcrans(3M).  Either for efficiency or for theory, the addrans(3M) functions are recommended for normal use over those in drand48(3), lcrans(3M), rand(3C), rand(3V), and random(3). 

Sun Release 4.0  —  Last change: 20 May 1989

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026