Oracle® Solaris Studio 12.4: Numerical Computation Guide

Exit Print View

Updated: January 2015
 
 

3.6.4 Random Number Facilities

There are three facilities for generating uniform pseudo-random numbers in 32-bit integer, single precision floating-point, and double precision floating-point formats:

  • The functions described in the addrans(3m) manual page are based on a family of table-driven additive random number generators.

  • The functions described in the lcrans(3m) manual page are based on a linear congruential random number generator.

  • The functions described in the mwcrans(3m) manual page are based on multiply-with-carry random number generators. These functions also include generators that supply uniform pseudo-random numbers in 64-bit integer formats.

In addition, the functions described on the shufrans(3m) manual page can be used in conjunction with any of these generators to shuffle an array of pseudo-random numbers, thereby providing even more randomness for applications that need it. Note that there is no facility for shuffling arrays of 64-bit integers.

Each of the random number facilities includes routines that generate one random number at a time, i.e., one per function call, as well as routines that generate an array of random numbers in a single call. The functions that generate one random number at a time deliver numbers that lie in the ranges shown in Table 3–17.

Table 3-17  Intervals for Single-Value Random Number Generators
Function
Lower Bound
Upper Bound
i_addran_
-2147483648
2147483647
r_addran_
0
0.9999999403953552246
d_addran_
0
0.9999999999999998890
i_lcran_
1
2147483646
r_lcran_
4.656612873077392578E-10
1
d_lcran_
4.656612875245796923E-10
0.9999999995343387127
i_mwcran_
0
2147483647
u_mwcran_
0
4294967295
i_llmwcran_
0
9223372036854775807
u_llmwcran_
0
18446744073709551615
r_mwcran_
0
0.9999999403953552246
d_mwcran_
0
0.9999999999999998890

The functions that generate an entire array of random numbers in a single call allow the user to specify the interval in which the generated numbers will lie. Appendix A, Examples gives several examples that show how to generate arrays of random numbers uniformly distributed over different intervals.

Note that the addrans and mwcrans generators are generally more efficient than the lcrans generators, but their theory is not as refined. “Random Number Generators: Good Ones Are Hard To Find”, by S. Park and K. Miller, Communications of the ACM, October 1988, discusses the theoretical properties of linear congruential algorithms. Additive random number generators are discussed in Volume 2 of Knuth's The Art of Computer Programming.