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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       drand48, erand48, jrand48, lcong48, lrand48, mrand48, nrand48,  seed48,
13       srand48 — generate uniformly distributed pseudo-random numbers
14

SYNOPSIS

16       #include <stdlib.h>
17
18       double drand48(void);
19       double erand48(unsigned short xsubi[3]);
20       long jrand48(unsigned short xsubi[3]);
21       void lcong48(unsigned short param[7]);
22       long lrand48(void);
23       long mrand48(void);
24       long nrand48(unsigned short xsubi[3]);
25       unsigned short *seed48(unsigned short seed16v[3]);
26       void srand48(long seedval);
27

DESCRIPTION

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

RETURN VALUE

114       As described in the DESCRIPTION above.
115

ERRORS

117       No errors are defined.
118
119       The following sections are informative.
120

EXAMPLES

122       None.
123

APPLICATION USAGE

125       These  functions  should  be  avoided whenever non-trivial requirements
126       (including safety) have to be fulfilled.
127

RATIONALE

129       None.
130

FUTURE DIRECTIONS

132       None.
133

SEE ALSO

135       initstate(), rand()
136
137       The Base Definitions volume of POSIX.1‐2017, <stdlib.h>
138
140       Portions of this text are reprinted and reproduced in  electronic  form
141       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
142       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
143       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
144       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
145       event of any discrepancy between this version and the original IEEE and
146       The Open Group Standard, the original IEEE and The Open Group  Standard
147       is  the  referee document. The original Standard can be obtained online
148       at http://www.opengroup.org/unix/online.html .
149
150       Any typographical or formatting errors that appear  in  this  page  are
151       most likely to have been introduced during the conversion of the source
152       files to man page format. To report such errors,  see  https://www.ker
153       nel.org/doc/man-pages/reporting_bugs.html .
154
155
156
157IEEE/The Open Group                  2017                          DRAND48(3P)
Impressum