📄 rng.texi
字号:
see,@itemize @asis@itemW. Petersen, "Lagged Fibonacci Random Number Generators for the NECSX-3", @cite{International Journal of High Speed Computing} (1994).@end itemize@end deffn@deffn {Generator} gsl_rng_borosh13This is the Borosh, Niederreiter random number generator. It is takenfrom Knuth's @cite{Seminumerical Algorithms}, 3rd Ed., pages106-108. Its sequence is,@tex\beforedisplay$$x_{n+1} = (a x_n) \,\hbox{mod}\, m$$\afterdisplay@end tex@ifinfo@examplex_@{n+1@} = (a x_n) mod m@end example@end ifinfo@noindentwith @math{a = 1812433253} and @c{$m = 2^{32}$}@math{m = 2^32}.The seed specifies the initial value, @c{$x_1$}@math{x_1}.@end deffn@deffn {Generator} gsl_rng_coveyouThis is the Coveyou random number generator. It is taken from Knuth's@cite{Seminumerical Algorithms}, 3rd Ed., Section 3.2.2. Its sequenceis,@tex\beforedisplay$$x_{n+1} = (x_n (x_n + 1)) \,\hbox{mod}\, m$$\afterdisplay@end tex@ifinfo@examplex_@{n+1@} = (x_n (x_n + 1)) mod m@end example@end ifinfo@noindentwith @c{$m = 2^{32}$}@math{m = 2^32}.The seed specifies the initial value, @c{$x_1$}@math{x_1}.@end deffn@deffn {Generator} gsl_rng_fishman18This is the Fishman, Moore III random number generator. It is taken fromKnuth's @cite{Seminumerical Algorithms}, 3rd Ed., pages 106-108. Itssequence is,@tex\beforedisplay$$x_{n+1} = (a x_n) \,\hbox{mod}\, m$$\afterdisplay@end tex@ifinfo@examplex_@{n+1@} = (a x_n) mod m@end example@end ifinfo@noindentwith @math{a = 62089911} and @c{$m = 2^{31}-1$}@math{m = 2^31 - 1}.The seed specifies the initial value, @c{$x_1$}@math{x_1}.@end deffn@deffn {Generator} gsl_rng_fishman20This is the Fishman random number generator. It is taken from Knuth's@cite{Seminumerical Algorithms}, 3rd Ed., page 108. Its sequence is,@tex\beforedisplay$$x_{n+1} = (a x_n) \,\hbox{mod}\, m$$\afterdisplay@end tex@ifinfo@examplex_@{n+1@} = (a x_n) mod m@end example@end ifinfo@noindentwith @math{a = 48271} and @c{$m = 2^{31}-1$}@math{m = 2^31 - 1}.The seed specifies the initial value, @c{$x_1$}@math{x_1}.@end deffn@deffn {Generator} gsl_rng_fishman2xThis is the L'Ecuyer--Fishman random number generator. It is taken fromKnuth's @cite{Seminumerical Algorithms}, 3rd Ed., page 108. Its sequenceis,@tex\beforedisplay$$z_{n+1} = (x_n - y_n) \,\hbox{mod}\, m$$\afterdisplay@end tex@ifinfo@examplez_@{n+1@} = (x_n - y_n) mod m@end example@end ifinfo@noindentwith @c{$m = 2^{31}-1$}@math{m = 2^31 - 1}.@math{x_n} and @math{y_n} are given by the @code{fishman20} and @code{lecuyer21} algorithms.The seed specifies the initial value, @c{$x_1$}@math{x_1}.@end deffn@deffn {Generator} gsl_rng_knuthran2This is a second-order multiple recursive generator described by Knuthin @cite{Seminumerical Algorithms}, 3rd Ed., page 108. Its sequence is,@tex\beforedisplay$$x_n = (a_1 x_{n-1} + a_2 x_{n-2}) \,\hbox{mod}\, m$$\afterdisplay@end tex@ifinfo@examplex_n = (a_1 x_@{n-1@} + a_2 x_@{n-2@}) mod m@end example@end ifinfo@noindentwith @math{a_1 = 271828183}, @math{a_2 = 314159269}, and @c{$m = 2^{31}-1$}@math{m = 2^31 - 1}.@end deffn@deffn {Generator} gsl_rng_knuthranThis is a second-order multiple recursive generator described by Knuthin @cite{Seminumerical Algorithms}, 3rd Ed., Section 3.6. Knuthprovides its C code.@end deffn@deffn {Generator} gsl_rng_lecuyer21This is the L'Ecuyer random number generator. It is taken from Knuth's@cite{Seminumerical Algorithms}, 3rd Ed., page 106-108. Its sequence is,@tex\beforedisplay$$x_{n+1} = (a x_n) \,\hbox{mod}\, m$$\afterdisplay@end tex@ifinfo@examplex_@{n+1@} = (a x_n) mod m@end example@end ifinfo@noindentwith @math{a = 40692} and @c{$m = 2^{31}-249$}@math{m = 2^31 - 249}.The seed specifies the initial value, @c{$x_1$}@math{x_1}.@end deffn@deffn {Generator} gsl_rng_waterman14This is the Waterman random number generator. It is taken from Knuth's@cite{Seminumerical Algorithms}, 3rd Ed., page 106-108. Its sequence is,@tex\beforedisplay$$x_{n+1} = (a x_n) \,\hbox{mod}\, m$$\afterdisplay@end tex@ifinfo@examplex_@{n+1@} = (a x_n) mod m@end example@end ifinfo@noindentwith @math{a = 1566083941} and @c{$m = 2^{32}$}@math{m = 2^32}.The seed specifies the initial value, @c{$x_1$}@math{x_1}.@end deffn@node Random Number Generator Performance@section Performance@comment@comment I made the original plot like this@comment ./benchmark > tmp; cat tmp | perl -n -e '($n,$s) = split(" ",$_); printf("%17s ",$n); print "-" x ($s/1e5), "\n";'@commentThe following table shows the relative performance of a selection theavailable random number generators. The fastest simulation qualitygenerators are @code{taus}, @code{gfsr4} and @code{mt19937}. Thegenerators which offer the best mathematically-proven quality are thosebased on the @sc{ranlux} algorithm.@comment The large number of generators based on single linear congruences are@comment represented by the @code{random} generator below. These generators are@comment fast but have the lowest statistical quality.@example1754 k ints/sec, 870 k doubles/sec, taus1613 k ints/sec, 855 k doubles/sec, gfsr41370 k ints/sec, 769 k doubles/sec, mt19937 565 k ints/sec, 571 k doubles/sec, ranlxs0 400 k ints/sec, 405 k doubles/sec, ranlxs1 490 k ints/sec, 389 k doubles/sec, mrg 407 k ints/sec, 297 k doubles/sec, ranlux 243 k ints/sec, 254 k doubles/sec, ranlxd1 251 k ints/sec, 253 k doubles/sec, ranlxs2 238 k ints/sec, 215 k doubles/sec, cmrg 247 k ints/sec, 198 k doubles/sec, ranlux389 141 k ints/sec, 140 k doubles/sec, ranlxd21852 k ints/sec, 935 k doubles/sec, ran3 813 k ints/sec, 575 k doubles/sec, ran0 787 k ints/sec, 476 k doubles/sec, ran1 379 k ints/sec, 292 k doubles/sec, ran2@end example@node Random Number Generator Examples@section ExamplesThe following program demonstrates the use of a random number generatorto produce uniform random numbers in range [0.0, 1.0),@example@verbatiminclude examples/rngunif.c@end example@noindentHere is the output of the program,@example$ ./a.out @verbatiminclude examples/rngunif.out@end example@noindentThe numbers depend on the seed used by the generator. The default seedcan be changed with the @code{GSL_RNG_SEED} environment variable toproduce a different stream of numbers. The generator itself can bechanged using the environment variable @code{GSL_RNG_TYPE}. Here is theoutput of the program using a seed value of 123 and themutiple-recursive generator @code{mrg},@example$ GSL_RNG_SEED=123 GSL_RNG_TYPE=mrg ./a.out @verbatiminclude examples/rngunif.2.out@end example@node Random Number References and Further Reading@section References and Further Reading@noindentThe subject of random number generation and testing is reviewedextensively in Knuth's @cite{Seminumerical Algorithms}.@itemize @asis@itemDonald E. Knuth, @cite{The Art of Computer Programming: SeminumericalAlgorithms} (Vol 2, 3rd Ed, 1997), Addison-Wesley, ISBN 0201896842.@end itemize@noindentFurther information is available in the review paper written by PierreL'Ecuyer,@itemize @asisP. L'Ecuyer, ``Random Number Generation'', Chapter 4 of theHandbook on Simulation, Jerry Banks Ed., Wiley, 1998, 93--137.@url{http://www.iro.umontreal.ca/~lecuyer/papers.html}in the file @file{handsim.ps}.@end itemize@noindentOn the World Wide Web, see the pLab home page(@url{http://random.mat.sbg.ac.at/}) for a lot of information on thestate-of-the-art in random number generation, and for numerous links tovarious "random" WWW sites.@noindentThe source code for the @sc{diehard} random number generator tests is alsoavailable online.@itemize @asis@item@cite{DIEHARD source code} G. Marsaglia,@item@url{http://stat.fsu.edu/pub/diehard/}@end itemize@noindentA comprehensive set of random number generator tests is available from@sc{nist},@itemize @asis@itemNIST Special Publication 800-22, "A Statistical Test Suite for theValidation of Random Number Generators and Pseudo Random NumberGenerators for Cryptographic Applications".@item@url{http://csrc.nist.gov/rng/}@end itemize@node Random Number Acknowledgements@section Acknowledgements@noindentThanks to Makoto Matsumoto, Takuji Nishimura and Yoshiharu Kurita formaking the source code to their generators (MT19937, MM&TN; TT800,MM&YK) available under the GNU General Public License. Thanks to MartinL@"uscher for providing notes and source code for the @sc{ranlxs} and@sc{ranlxd} generators.@comment lcg@comment [ LCG(n) := n * 69069 mod (2^32) ]@comment First 6: [69069, 475559465, 2801775573, 1790562961, 3104832285, 4238970681]@comment %2^31-1 69069, 475559465, 654291926, 1790562961, 957348638, 2091487034@comment mrg@comment [q([x1, x2, x3, x4, x5]) := [107374182 mod 2147483647 * x1 + 104480 mod 2147483647 * x5, x1, x2, x3, x4]]@comment@comment cmrg@comment [q1([x1,x2,x3]) := [63308 mod 2147483647 * x2 -183326 mod 2147483647 * x3, x1, x2],@comment q2([x1,x2,x3]) := [86098 mod 2145483479 * x1 -539608 mod 2145483479 * x3, x1, x2] ]@comment initial for q1 is [69069, 475559465, 654291926]@comment initial for q2 is [1790562961, 959348806, 2093487202]@comment tausworthe@comment [ b1(x) := rsh(xor(lsh(x, 13), x), 19),@comment q1(x) := xor(lsh(and(x, 4294967294), 12), b1(x)),@comment b2(x) := rsh(xor(lsh(x, 2), x), 25),@comment q2(x) := xor(lsh(and(x, 4294967288), 4), b2(x)),@comment b3(x) := rsh(xor(lsh(x, 3), x), 11),@comment q3(x) := xor(lsh(and(x, 4294967280), 17), b3(x)) ]@comment [s1, s2, s3] = [600098857, 1131373026, 1223067536] @comment [2948905028, 441213979, 394017882]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -