1DRAND48(3)                 Linux Programmer's Manual                DRAND48(3)
2
3
4

NAME

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

SYNOPSIS

10       #include <stdlib.h>
11
12       double drand48(void);
13
14       double erand48(unsigned short xsubi[3]);
15
16       long int lrand48(void);
17
18       long int nrand48(unsigned short xsubi[3]);
19
20       long int mrand48(void);
21
22       long int jrand48(unsigned short xsubi[3]);
23
24       void srand48(long int seedval);
25
26       unsigned short *seed48(unsigned short seed16v[3]);
27
28       void lcong48(unsigned short param[7]);
29
30   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
31
32       All functions shown above: _XOPEN_SOURCE
33           || /* Glibc since 2.19: */ _DEFAULT_SOURCE
34           || /* Glibc versions <= 2.19: */ _SVID_SOURCE
35

DESCRIPTION

37       These functions generate pseudo-random numbers using the linear congru‐
38       ential algorithm and 48-bit integer arithmetic.
39
40       The  drand48() and erand48() functions return nonnegative double-preci‐
41       sion floating-point values  uniformly  distributed  over  the  interval
42       [0.0, 1.0).
43
44       The  lrand48() and nrand48() functions return nonnegative long integers
45       uniformly distributed over the interval [0, 2^31).
46
47       The mrand48() and jrand48() functions return signed long integers  uni‐
48       formly distributed over the interval [-2^31, 2^31).
49
50       The  srand48(),  seed48()  and  lcong48()  functions are initialization
51       functions, one of  which  should  be  called  before  using  drand48(),
52       lrand48()   or  mrand48().   The  functions  erand48(),  nrand48()  and
53       jrand48() do not require an initialization function to be called first.
54
55       All the functions work by generating a sequence of 48-bit integers, Xi,
56       according to the linear congruential formula:
57
58           Xn+1 = (aXn + c) mod m, where n >= 0
59
60       The  parameter  m = 2^48, hence 48-bit integer arithmetic is performed.
61       Unless lcong48() is called, a and c are given by:
62
63           a = 0x5DEECE66D
64           c = 0xB
65
66       The value returned  by  any  of  the  functions  drand48(),  erand48(),
67       lrand48(),  nrand48(), mrand48() or jrand48() is computed by first gen‐
68       erating the next 48-bit Xi in the sequence.  Then the appropriate  num‐
69       ber  of  bits,  according  to  the type of data item to be returned, is
70       copied from the high-order bits of Xi and transformed into the returned
71       value.
72
73       The  functions drand48(), lrand48() and mrand48() store the last 48-bit
74       Xi generated in an internal buffer.  The functions erand48(), nrand48()
75       and  jrand48()  require  the calling program to provide storage for the
76       successive Xi values in the array argument xsubi.   The  functions  are
77       initialized  by  placing  the initial value of Xi into the array before
78       calling the function for the first time.
79
80       The initializer function srand48() sets the high order 32-bits of Xi to
81       the  argument  seedval.  The low order 16-bits are set to the arbitrary
82       value 0x330E.
83
84       The initializer function seed48() sets the value of Xi  to  the  48-bit
85       value  specified  in the array argument seed16v.  The previous value of
86       Xi is copied into an internal buffer and a pointer to  this  buffer  is
87       returned by seed48().
88
89       The  initialization  function lcong48() allows the user to specify ini‐
90       tial values for Xi, a and c.  Array argument elements param[0-2]  spec‐
91       ify  Xi,  param[3-5]  specify  a,  and  param[6]  specifies  c.   After
92       lcong48() has been called, a subsequent call  to  either  srand48()  or
93       seed48() will restore the standard values of a and c.
94

ATTRIBUTES

96       For   an   explanation   of   the  terms  used  in  this  section,  see
97       attributes(7).
98
99       ┌──────────────────────┬───────────────┬────────────────────────┐
100Interface             Attribute     Value                  
101       ├──────────────────────┼───────────────┼────────────────────────┤
102drand48(), erand48(), │ Thread safety │ MT-Unsafe race:drand48 │
103lrand48(), nrand48(), │               │                        │
104mrand48(), jrand48(), │               │                        │
105srand48(), seed48(),  │               │                        │
106lcong48()             │               │                        │
107       └──────────────────────┴───────────────┴────────────────────────┘
108       The above functions record global state information for the random num‐
109       ber generator, so they are not thread-safe.
110

CONFORMING TO

112       POSIX.1-2001, POSIX.1-2008, SVr4.
113

SEE ALSO

115       rand(3), random(3)
116

COLOPHON

118       This  page  is  part of release 4.16 of the Linux man-pages project.  A
119       description of the project, information about reporting bugs,  and  the
120       latest     version     of     this    page,    can    be    found    at
121       https://www.kernel.org/doc/man-pages/.
122
123
124
125                                  2017-09-15                        DRAND48(3)
Impressum