1DRAND48(3) Linux Programmer's Manual DRAND48(3)
2
3
4
6 drand48, erand48, lrand48, nrand48, mrand48, jrand48, srand48, seed48,
7 lcong48 - generate uniformly distributed pseudo-random numbers
8
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: _SVID_SOURCE || _XOPEN_SOURCE
33
35 These functions generate pseudo-random numbers using the linear congru‐
36 ential algorithm and 48-bit integer arithmetic.
37
38 The drand48() and erand48() functions return nonnegative double-preci‐
39 sion floating-point values uniformly distributed between [0.0, 1.0).
40
41 The lrand48() and nrand48() functions return nonnegative long integers
42 uniformly distributed between 0 and 2^31.
43
44 The mrand48() and jrand48() functions return signed long integers uni‐
45 formly distributed between -2^31 and 2^31.
46
47 The srand48(), seed48() and lcong48() functions are initialization
48 functions, one of which should be called before using drand48(),
49 lrand48() or mrand48(). The functions erand48(), nrand48() and
50 jrand48() do not require an initialization function to be called first.
51
52 All the functions work by generating a sequence of 48-bit integers, Xi,
53 according to the linear congruential formula:
54
55 Xn+1 = (aXn + c) mod m, where n >= 0
56
57 The parameter m = 2^48, hence 48-bit integer arithmetic is performed.
58 Unless lcong48() is called, a and c are given by:
59
60 a = 0x5DEECE66D
61 c = 0xB
62
63 The value returned by any of the functions drand48(), erand48(),
64 lrand48(), nrand48(), mrand48() or jrand48() is computed by first gen‐
65 erating the next 48-bit Xi in the sequence. Then the appropriate num‐
66 ber of bits, according to the type of data item to be returned, is
67 copied from the high-order bits of Xi and transformed into the returned
68 value.
69
70 The functions drand48(), lrand48() and mrand48() store the last 48-bit
71 Xi generated in an internal buffer. The functions erand48(), nrand48()
72 and jrand48() require the calling program to provide storage for the
73 successive Xi values in the array argument xsubi. The functions are
74 initialized by placing the initial value of Xi into the array before
75 calling the function for the first time.
76
77 The initializer function srand48() sets the high order 32-bits of Xi to
78 the argument seedval. The low order 16-bits are set to the arbitrary
79 value 0x330E.
80
81 The initializer function seed48() sets the value of Xi to the 48-bit
82 value specified in the array argument seed16v. The previous value of
83 Xi is copied into an internal buffer and a pointer to this buffer is
84 returned by seed48().
85
86 The initialization function lcong48() allows the user to specify ini‐
87 tial values for Xi, a and c. Array argument elements param[0-2] spec‐
88 ify Xi, param[3-5] specify a, and param[6] specifies c. After
89 lcong48() has been called, a subsequent call to either srand48() or
90 seed48() will restore the standard values of a and c.
91
93 SVr4, POSIX.1-2001.
94
96 These functions are declared obsolete by SVID 3, which states that
97 rand(3) should be used instead.
98
100 rand(3), random(3)
101
103 This page is part of release 3.25 of the Linux man-pages project. A
104 description of the project, and information about reporting bugs, can
105 be found at http://www.kernel.org/doc/man-pages/.
106
107
108
109 2007-07-26 DRAND48(3)