1 .\" Copyright (c) 1993 Martin Birgmeier
2 .\" All rights reserved.
4 .\" You may redistribute unmodified or modified versions of this source
5 .\" code provided that the above copyright notice and this and the
6 .\" following conditions are retained.
8 .\" This software is provided ``as is'', and comes with no warranties
9 .\" of any kind. I shall in no event be liable for anything that happens
10 .\" to anyone/anything when using this software.
12 .\" @(#)rand48.3 V1.0 MB 8 Oct 1993
13 .\" $FreeBSD: src/lib/libc/gen/rand48.3,v 1.8.2.6 2003/03/15 15:11:05 trhodes Exp $
14 .\" $DragonFly: src/lib/libc/gen/rand48.3,v 1.4 2008/04/20 19:21:42 swildner Exp $
29 .Nd pseudo random number generators and initialization routines
37 .Fn erand48 "unsigned short xseed[3]"
41 .Fn nrand48 "unsigned short xseed[3]"
45 .Fn jrand48 "unsigned short xseed[3]"
47 .Fn srand48 "long seed"
48 .Ft "unsigned short *"
49 .Fn seed48 "unsigned short xseed[3]"
51 .Fn lcong48 "unsigned short p[7]"
55 family of functions generates pseudo-random numbers using a linear
56 congruential algorithm working on integers 48 bits in size.
58 particular formula employed is
59 r(n+1) = (a * r(n) + c) mod m
60 where the default values are
61 for the multiplicand a = 0xfdeece66d = 25214903917 and
62 the addend c = 0xb = 11.
63 The modulo is always fixed at m = 2 ** 48.
64 r(n) is called the seed of the random number generator.
66 For all the six generator routines described next, the first
67 computational step is to perform a single iteration of the algorithm.
74 return values of type double.
75 The full 48 bits of r(n+1) are
76 loaded into the mantissa of the returned value, with the exponent set
77 such that the values produced lie in the interval [0.0, 1.0).
84 return values of type long in the range
85 [0, 2**31-1]. The high-order (31) bits of
86 r(n+1) are loaded into the lower bits of the returned value, with
87 the topmost (sign) bit set to zero.
94 return values of type long in the range
95 [-2**31, 2**31-1]. The high-order (32) bits of
96 r(n+1) are loaded into the returned value.
104 use an internal buffer to store r(n). For these functions
105 the initial value of r(0) = 0x1234abcd330e = 20017429951246.
112 use a user-supplied buffer to store the seed r(n),
113 which consists of an array of 3 shorts, where the zeroth member
114 holds the least significant bits.
116 All functions share the same multiplicand and addend.
121 is used to initialize the internal buffer r(n) of
126 such that the 32 bits of the seed value are copied into the upper 32 bits
127 of r(n), with the lower 16 bits of r(n) arbitrarily being set to 0x330e.
128 Additionally, the constant multiplicand and addend of the algorithm are
129 reset to the default values given above.
134 also initializes the internal buffer r(n) of
139 but here all 48 bits of the seed can be specified in an array of 3 shorts,
140 where the zeroth member specifies the lowest bits.
142 the constant multiplicand and addend of the algorithm are
143 reset to the default values given above.
147 returns a pointer to an array of 3 shorts which contains the old seed.
148 This array is statically allocated, thus its contents are lost after
154 allows full control over the multiplicand and addend used in
167 An array of 7 shorts is passed as argument; the first three shorts are
168 used to initialize the seed; the second three are used to initialize the
169 multiplicand; and the last short is used to initialize the addend.
170 It is thus not possible to use values greater than 0xffff as the addend.
172 Note that all three methods of seeding the random number generator
173 always also set the multiplicand and addend for any of the six
176 For a more powerful random number generator, see