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       double erand48(unsigned short xsubi[3]);
14
15       long lrand48(void);
16       long nrand48(unsigned short xsubi[3]);
17
18       long mrand48(void);
19       long jrand48(unsigned short xsubi[3]);
20
21       void srand48(long seedval);
22       unsigned short *seed48(unsigned short seed16v[3]);
23       void lcong48(unsigned short param[7]);
24
25   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
26
27       All functions shown above:
28           _XOPEN_SOURCE
29               || /* Glibc since 2.19: */ _DEFAULT_SOURCE
30               || /* Glibc <= 2.19: */ _SVID_SOURCE
31

DESCRIPTION

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

ATTRIBUTES

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

CONFORMING TO

107       POSIX.1-2001, POSIX.1-2008, SVr4.
108

SEE ALSO

110       rand(3), random(3)
111

COLOPHON

113       This page is part of release 5.13 of the Linux  man-pages  project.   A
114       description  of  the project, information about reporting bugs, and the
115       latest    version    of    this    page,    can     be     found     at
116       https://www.kernel.org/doc/man-pages/.
117
118
119
120                                  2021-03-22                        DRAND48(3)
Impressum