1drand48(3C)              Standard C Library Functions              drand48(3C)
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
15       double erand48(unsigned short x(i)[3]);
16
17
18       long lrand48(void)
19
20
21       long nrand48(unsigned short x(i)[3]);
22
23
24       long mrand48(void)
25
26
27       long jrand48(unsigned short x(i)[3]);
28
29
30       void srand48(long seedval);
31
32
33       unsigned short *seed48(unsigned short seed16v[3]);
34
35
36       void lcong48(unsigned short param[7]);
37
38

DESCRIPTION

40       This family of functions  generates  pseudo-random  numbers  using  the
41       well-known linear congruential algorithm and 48-bit integer arithmetic.
42
43
44       Functions  drand48() and erand48() return non-negative double-precision
45       floating-point values uniformly distributed  over  the  interval  [0.0,
46       1.0).
47
48
49       Functions  lrand48()  and  nrand48()  return non-negative long integers
50       uniformly distributed over the interval [0, 2  ^31 ].
51
52
53       Functions mrand48() and jrand48() return signed long integers uniformly
54       distributed over the interval [-2 ^31  , 2 ^31  ].
55
56
57       Functions  srand48(),  seed48(), and lcong48() are initialization entry
58       points, one  of  which  should  be  invoked  before  either  drand48(),
59       lrand48(),  or  mrand48()  is  called.  (Although it is not recommended
60       practice, constant default initializer values will be supplied automat‐
61       ically  if drand48(), lrand48(), or mrand48() is called without a prior
62       call to an initialization entry point.) Functions erand48(), nrand48(),
63       and jrand48() do not require an initialization entry point to be called
64       first.
65
66
67       All the routines work by generating a sequence of 48-bit  integer  val‐
68       ues, X(i ), according to the linear congruential formula
69
70
71       X(n+1)= (aX (n)+c)(mod m) n>=0.
72
73
74       The  parameter  m = 2^48; hence 48-bit integer arithmetic is performed.
75       Unless lcong48() has been invoked, the multiplier value aand the addend
76       value care given by
77         a = 5DEECE66D(16) = 273673163155(8)
78         c = B(16) = 13(8)
79
80
81       The  value  returned  by  any  of  the  functions drand48(), erand48(),
82       lrand48(), nrand48(), mrand48(), or jrand48() is computed by first gen‐
83       erating the next 48-bit X(i) in the sequence. Then the appropriate num‐
84       ber of bits, according to the type of data item  to  be  returned,  are
85       copied from the high-order (leftmost) bits of X(i) and transformed into
86       the returned value.
87
88
89       The functions drand48(), lrand48(), and mrand48() store the last 48-bit
90       X(i) generated in an internal buffer. X(i) must be initialized prior to
91       being  invoked.  The  functions  erand48(),  nrand48(),  and  jrand48()
92       require  the calling program to provide storage for the successive X(i)
93       values in the array specified as an argument  when  the  functions  are
94       invoked. These routines do not have to be initialized; the calling pro‐
95       gram must place the desired initial value of X(i) into  the  array  and
96       pass  it  as  an  argument.  By  using  different  arguments, functions
97       erand48(), nrand48(), and jrand48() allow separate modules of  a  large
98       program  to  generate several independent streams of pseudo-random num‐
99       bers, that is, the sequence of numbers in each stream will  not  depend
100       upon  how  many times the routines have been called to generate numbers
101       for the other streams.
102
103
104       The initializer function srand48() sets the high-order 32 bits of  X(i)
105       to the 32 bits contained in its argument. The low-order 16 bits of X(i)
106       are set to the arbitrary value 330E(16) .
107
108
109       The initializer function seed48() sets the value of X(i) to the  48-bit
110       value  specified in the argument array. In addition, the previous value
111       of X(i) is copied into a 48-bit internal buffer, used only by seed48(),
112       and  a  pointer  to this buffer is the value returned by seed48(). This
113       returned pointer, which can just be ignored if not needed, is useful if
114       a  program  is to be restarted from a given point at some future time —
115       use the pointer to get at and store the last X(i) value, and  then  use
116       this   value  to  reinitialize  using  seed48()  when  the  program  is
117       restarted.
118
119
120       The initialization function lcong48() allows the user  to  specify  the
121       initial  X(i)  the multiplier value a, and the addend value c. Argument
122       array elements param[0-2] specify X(i), param[3-5] specify  the  multi‐
123       plier  a,  and  param[6] specifies the 16-bit addend c. After lcong48()
124       has been called, a subsequent call to either srand48() or seed48() will
125       restore  the ``standard'' multiplier and addend values, a and c, speci‐
126       fied above.
127

ATTRIBUTES

129       See attributes(5) for descriptions of the following attributes:
130
131
132
133
134       ┌─────────────────────────────┬─────────────────────────────┐
135ATTRIBUTE TYPE         ATTRIBUTE VALUE        
136       ├─────────────────────────────┼─────────────────────────────┤
137       │Interface Stability          │Standard                     │
138       ├─────────────────────────────┼─────────────────────────────┤
139       │MT-Level                     │Safe                         │
140       └─────────────────────────────┴─────────────────────────────┘
141

SEE ALSO

143       rand(3C), attributes(5), standards(5)
144
145
146
147SunOS 5.11                        24 Jul 2002                      drand48(3C)
Impressum