1drand48(3)                 Library Functions 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

LIBRARY

10       Standard C library (libc, -lc)
11

SYNOPSIS

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

DESCRIPTION

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

ATTRIBUTES

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

STANDARDS

110       POSIX.1-2008.
111

HISTORY

113       POSIX.1-2001, SVr4.
114

SEE ALSO

116       rand(3), random(3)
117
118
119
120Linux man-pages 6.04              2023-03-30                        drand48(3)
Impressum