1 .\" $NetBSD: rand48.3,v 1.11 2006/03/31 11:43:54 drochner Exp $
3 .\" Copyright (c) 1993 Martin Birgmeier
4 .\" All rights reserved.
6 .\" You may redistribute unmodified or modified versions of this source
7 .\" code provided that the above copyright notice and this and the
8 .\" following conditions are retained.
10 .\" This software is provided ``as is'', and comes with no warranties
11 .\" of any kind. I shall in no event be liable for anything that happens
12 .\" to anyone/anything when using this software.
27 .Nd pseudo-random number generators and initialization routines
35 .Fn erand48 "unsigned short xseed[3]"
39 .Fn nrand48 "unsigned short xseed[3]"
43 .Fn jrand48 "unsigned short xseed[3]"
45 .Fn srand48 "long seed"
46 .Ft "unsigned short *"
47 .Fn seed48 "unsigned short xseed[3]"
49 .Fn lcong48 "unsigned short p[7]"
53 family of functions generates pseudo-random numbers using a linear
54 congruential algorithm working on integers 48 bits in size.
55 The particular formula employed is
56 r(n+1) = (a * r(n) + c) mod m
57 where the default values are
58 for the multiplicand a = 0x5deece66d = 25214903917 and
59 the addend c = 0xb = 11.
60 The modulus is always fixed at m = 2 ** 48.
61 r(n) is called the seed of the random number generator.
63 For all the six generator routines described next, the first
64 computational step is to perform a single iteration of the algorithm.
69 return values of type double.
70 The full 48 bits of r(n+1) are loaded into the mantissa of the
71 returned value, with the exponent set such that the values produced
72 lie in the interval [0.0, 1.0).
77 return values of type long in the range [0, 2**31-1].
78 The high-order (31) bits of r(n+1) are loaded into the lower bits
79 of the returned value, with the topmost (sign) bit set to zero.
84 return values of type long in the range [-2**31, 2**31-1].
85 The high-order (32) bits of r(n+1) are loaded into the returned value.
91 use an internal buffer to store r(n).
93 the initial value of r(0) = 0x1234abcd330e = 20017429951246.
100 use a user-supplied buffer to store the seed r(n), which consists
101 of an array of 3 shorts, where the zeroth member holds the least
104 All functions share the same multiplicand and addend.
107 is used to initialize the internal buffer r(n) of
112 such that the 32 bits of the seed value are copied into the upper 32 bits
113 of r(n), with the lower 16 bits of r(n) arbitrarily being set to 0x330e.
114 Additionally, the constant multiplicand and addend of the algorithm are
115 reset to the default values given above.
118 also initializes the internal buffer r(n) of
123 but here all 48 bits of the seed can be specified in an array of 3 shorts,
124 where the zeroth member specifies the lowest bits.
125 Again, the constant multiplicand and addend of the algorithm are
126 reset to the default values given above.
128 returns a pointer to an array of 3 shorts which contains the old seed.
129 This array is statically allocated, thus its contents are lost after
135 allows full control over the multiplicand and addend used in
148 An array of 7 shorts is passed as parameter; the first three shorts are
149 used to initialize the seed; the second three are used to initialize the
150 multiplicand; and the last short is used to initialize the addend.
151 It is thus not possible to use values greater than 0xffff as the addend.
153 Note that all three methods of seeding the random number generator
154 always also set the multiplicand and addend for any of the six
157 For a more powerful random number generator, see