From c16b89d7704fd46232be094c24ad118cde20abaa Mon Sep 17 00:00:00 2001 From: Kerooker Date: Fri, 29 Nov 2019 11:11:10 -0300 Subject: [PATCH] Fix XorWowRandom documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit changes XorWowRandom.kt documentation to include a HTTPS link instead of a HTTP link, for security purposes. This commit also changes the same documentation to reflect the real cycles from the `xorwow` algorithm: Simple and very fast (125 million/sec), the elements in its cycle of 2^192 − 2^32 easily pass all the tests in Diehard. Marsaglia, G. 2003. Xorshift RNGs. J. Statis. Soft. 8, 14, p. 5 At last, this commit explicits which part of the code is the implementation of the mentioned algorithm. Closes KT-35175 --- libraries/stdlib/src/kotlin/random/XorWowRandom.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libraries/stdlib/src/kotlin/random/XorWowRandom.kt b/libraries/stdlib/src/kotlin/random/XorWowRandom.kt index 2f40960f033..592745ebb71 100644 --- a/libraries/stdlib/src/kotlin/random/XorWowRandom.kt +++ b/libraries/stdlib/src/kotlin/random/XorWowRandom.kt @@ -6,11 +6,14 @@ package kotlin.random /** - * Random number generator, algorithm "xorwow" from p. 5 of Marsaglia, "Xorshift RNGs". + * Random number generator, using Marsaglia's "xorwow" algorithm * - * Cycles after 2^160 * (2^32-1) repetitions. + * Cycles after 2^192 - 2^32 repetitions. + * + * For more details, see Marsaglia, George (July 2003). "Xorshift RNGs". Journal of Statistical Software. 8 (14). doi:10.18637/jss.v008.i14 + * + * Available at https://www.jstatsoft.org/v08/i14/paper * - * See http://www.jstatsoft.org/v08/i14/paper for details. */ internal class XorWowRandom internal constructor( @@ -33,6 +36,8 @@ internal constructor( } override fun nextInt(): Int { + // Equivalent to the xorxow algorithm + // From Marsaglia, G. 2003. Xorshift RNGs. J. Statis. Soft. 8, 14, p. 5 var t = x t = t xor (t ushr 2) x = y