正在加载图片...
7.1 Uniform Deviates 281 iy 1 ivo OUTPUT RAN 3 ② .com or call (including this one) 19881992 11-800-872 g Cambridge iv3l to any server computer, -7423(North America users to make one paper from NUMERICAL RECIPES IN C: e University Press. THE ART Figure 7.1.1.Shuffling procedure used in ran1 to break up sequential correlations in the Minimal Standard generator.Circled numbers indicate the sequence of events:On each call,the random number 9 Programs in iy is used to choose a random element in the array iv.That element becomes the output random ictly proh number,and also is the next iy.Its spot in iv is refilled from the Minimal Standard routine. either of them (call it m).A trick to avoid an intermediate value that overflows the to dir integer wordsize is to subtract rather than add,and then add back the constant m-1 if the result is 0,so as to wrap around into the desired interval 0,...,m-1. OF SCIENTIFIC COMPUTING(ISBN Notice that it is not necessary that this wrapped subtraction be able to reach 1988-19920 all values 0,...,m-1 from every value of the first sequence.Consider the absurd extreme case where the value subtracted was only between I and 10:The resulting 10-521 sequence would still be no less random than the first sequence by itself.As a practical matter it is only necessary that the second sequence have a range covering substantially all of the range of the first.L'Ecuyer recommends the use of the two Numerical Recipes 43198-5 generators m1=2147483563(with a1=40014,q1=53668,r1=12211)and m2=2147483399(with a2=40692,92=52774,r2=3791).Both moduli (outside are slightly less than231.The periods m1-1=2×3×7×631×81031and North Software. m2-1=2×19×31×1019×1789 share only the factor2,so the period of the combined generator is2.3x 1018.For present computers,period exhaustion is a practical impossibility. visit website Combining the two generators breaks up serial correlations to a considerable machine extent.We nevertheless recommend the additional shuffle that is implemented in the following routine,ran2.We think that,within the limits of its floating-point precision,ran2 provides perfect random numbers,a practical definition of"perfect" is that we will pay $1000 to the first reader who convinces us otherwise (by finding a statistical test that ran2 fails in a nontrivial way,excluding the ordinary limitations of a machine's floating-point representation).7.1 Uniform Deviates 281 Permission is granted for internet users to make one paper copy for their own personal use. Further reproduction, or any copyin Copyright (C) 1988-1992 by Cambridge University Press. Programs Copyright (C) 1988-1992 by Numerical Recipes Software. Sample page from NUMERICAL RECIPES IN C: THE ART OF SCIENTIFIC COMPUTING (ISBN 0-521-43108-5) g of machine￾readable files (including this one) to any server computer, is strictly prohibited. To order Numerical Recipes books or CDROMs, visit website http://www.nr.com or call 1-800-872-7423 (North America only), or send email to directcustserv@cambridge.org (outside North America). OUTPUT RAN 1 3 2 iy iv0 iv31 Figure 7.1.1. Shuffling procedure used in ran1 to break up sequential correlations in the Minimal Standard generator. Circled numbers indicate the sequence of events: On each call, the random number in iy is used to choose a random element in the array iv. That element becomes the output random number, and also is the next iy. Its spot in iv is refilled from the Minimal Standard routine. either of them (call it m). A trick to avoid an intermediate value that overflows the integer wordsize is to subtract rather than add, and then add back the constant m − 1 if the result is ≤ 0, so as to wrap around into the desired interval 0,...,m − 1. Notice that it is not necessary that this wrapped subtraction be able to reach all values 0,...,m − 1 from every value of the first sequence. Consider the absurd extreme case where the value subtracted was only between 1 and 10: The resulting sequence would still be no less random than the first sequence by itself. As a practical matter it is only necessary that the second sequence have a range covering substantially all of the range of the first. L’Ecuyer recommends the use of the two generators m1 = 2147483563 (with a1 = 40014, q1 = 53668, r1 = 12211) and m2 = 2147483399 (with a2 = 40692, q2 = 52774, r2 = 3791). Both moduli are slightly less than 231. The periods m1 − 1=2 × 3 × 7 × 631 × 81031 and m2 − 1=2 × 19 × 31 × 1019 × 1789 share only the factor 2, so the period of the combined generator is ≈ 2.3 × 1018. For present computers, period exhaustion is a practical impossibility. Combining the two generators breaks up serial correlations to a considerable extent. We nevertheless recommend the additional shuffle that is implemented in the following routine, ran2. We think that, within the limits of its floating-point precision, ran2 provides perfect random numbers; a practical definition of “perfect” is that we will pay $1000 to the first reader who convinces us otherwise (by finding a statistical test that ran2 fails in a nontrivial way, excluding the ordinary limitations of a machine’s floating-point representation)
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有