1DRAND48(P)                 POSIX Programmer's Manual                DRAND48(P)
2
3
4

NAME

6       drand48,  erand48, jrand48, lcong48, lrand48, mrand48, nrand48, seed48,
7       srand48 - generate uniformly distributed pseudo-random numbers
8

SYNOPSIS

10       #include <stdlib.h>
11
12       double drand48(void);
13       double erand48(unsigned short xsubi[3]);
14       long jrand48(unsigned short xsubi[3]);
15       void lcong48(unsigned short param[7]);
16       long lrand48(void);
17       long mrand48(void);
18       long nrand48(unsigned short xsubi[3]);
19       unsigned short *seed48(unsigned short seed16v[3]);
20       void srand48(long seedval);
21
22

DESCRIPTION

24       This family of functions shall generate pseudo-random numbers  using  a
25       linear congruential algorithm and 48-bit integer arithmetic.
26
27       The  drand48()  and erand48() functions shall return non-negative, dou‐
28       ble-precision, floating-point values, uniformly  distributed  over  the
29       interval [0.0,1.0).
30
31       The  lrand48()  and nrand48() functions shall return non-negative, long
32       integers, uniformly distributed over the interval [0,2**31).
33
34       The mrand48() and jrand48() functions shall return signed long integers
35       uniformly distributed over the interval [-2**31,2**31).
36
37       The  srand48(),  seed48(),  and  lcong48() functions are initialization
38       entry points, one of which should be invoked before  either  drand48(),
39       lrand48(),  or  mrand48()  is  called.  (Although it is not recommended
40       practice, constant default initializer values shall be  supplied  auto‐
41       matically  if  drand48(),  lrand48(),  or mrand48() is called without a
42       prior call to an initialization entry point.) The erand48(), nrand48(),
43       and jrand48() functions do not require an initialization entry point to
44       be called first.
45
46       All the routines work by generating a sequence of 48-bit  integer  val‐
47       ues,  X_i , according to the linear congruential formula: X_n+1 = (aX_n
48       + c)_mod m   n>= 0
49
50       The parameter m = 2**48; hence 48-bit integer arithmetic is  performed.
51       Unless  lcong48()  is  invoked,  the  multiplier value a and the addend
52       value c are given by: a = 5DEECE66D_16 = 273673163155_8
53
54       c = B_16 = 13_8
55
56       The value returned by  any  of  the  drand48(),  erand48(),  jrand48(),
57       lrand48(),  mrand48(), or nrand48() functions is computed by first gen‐
58       erating the next 48-bit X_i in the sequence. Then the appropriate  num‐
59       ber  of  bits,  according  to the type of data item to be returned, are
60       copied from the high-order (leftmost) bits of X_i and transformed  into
61       the returned value.
62
63       The drand48(), lrand48(), and mrand48() functions store the last 48-bit
64       X_i generated in an internal buffer; that is why the application  shall
65       ensure   that  these  are  initialized  prior  to  being  invoked.  The
66       erand48(), nrand48(), and jrand48() functions require the calling  pro‐
67       gram  to  provide  storage  for  the successive X_i values in the array
68       specified as an argument when the functions are invoked.  That  is  why
69       these  routines  do  not  have  to  be initialized; the calling program
70       merely has to place the desired initial value of X_i into the array and
71       pass  it  as  an  argument.  By  using  different arguments, erand48(),
72       nrand48(), and jrand48() allow separate modules of a large  program  to
73       generate several independent streams of pseudo-random numbers; that is,
74       the sequence of numbers in each stream shall not depend upon  how  many
75       times  the  routines  are  called  to  generate  numbers  for the other
76       streams.
77
78       The initializer function srand48() sets the high-order 32 bits  of  X_i
79       to  the  low-order  32 bits contained in its argument. The low-order 16
80       bits of X_i are set to the arbitrary value 330E_16.
81
82       The initializer function seed48() sets the value of X_i to  the  48-bit
83       value specified in the argument array. The low-order 16 bits of X_i are
84       set to the low-order 16 bits of seed16v[0].  The mid-order 16  bits  of
85       X_i  are  set to the low-order 16 bits of seed16v[1]. The high-order 16
86       bits of X_i are set to the low-order 16 bits of  seed16v[2].  In  addi‐
87       tion,  the  previous value of X_i is copied into a 48-bit internal buf‐
88       fer, used only by seed48(), and a pointer to this buffer is  the  value
89       returned  by seed48(). This returned pointer, which can just be ignored
90       if not needed, is useful if a program is to be restarted from  a  given
91       point  at some future time-use the pointer to get at and store the last
92       X_i value, and then use this value to reinitialize  via  seed48()  when
93       the program is restarted.
94
95       The  initializer function lcong48() allows the user to specify the ini‐
96       tial X_i , the multiplier value a, and the addend  value  c.   Argument
97       array  elements  param[0-2] specify X_i , param[3-5] specify the multi‐
98       plier a, and param[6] specifies the 16-bit addend c. After lcong48() is
99       called, a subsequent call to either srand48() or seed48() shall restore
100       the standard multiplier and addend values, a and c, specified above.
101
102       The drand48(), lrand48(), and mrand48() functions  need  not  be  reen‐
103       trant.  A function that is not required to be reentrant is not required
104       to be thread-safe.
105

RETURN VALUE

107       As described in the DESCRIPTION above.
108

ERRORS

110       No errors are defined.
111
112       The following sections are informative.
113

EXAMPLES

115       None.
116

APPLICATION USAGE

118       None.
119

RATIONALE

121       None.
122

FUTURE DIRECTIONS

124       None.
125

SEE ALSO

127       rand()  ,  the  Base  Definitions   volume   of   IEEE Std 1003.1-2001,
128       <stdlib.h>
129
131       Portions  of  this text are reprinted and reproduced in electronic form
132       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
133       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
134       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
135       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
136       event of any discrepancy between this version and the original IEEE and
137       The  Open Group Standard, the original IEEE and The Open Group Standard
138       is the referee document. The original Standard can be  obtained  online
139       at http://www.opengroup.org/unix/online.html .
140
141
142
143IEEE/The Open Group                  2003                           DRAND48(P)
Impressum