]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
document source of fast rng
authorAlan T. DeKok <aland@freeradius.org>
Mon, 22 Jan 2024 19:31:07 +0000 (14:31 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 22 Jan 2024 23:45:05 +0000 (18:45 -0500)
src/lib/util/rand.c

index db2267200361ecac8d666f8d6df7b17a46a72b17..fbe9ecca743fb8743a772541678e2a2ac395522a 100644 (file)
@@ -258,6 +258,25 @@ while (p < end) { \
        }
 }
 
+
+/*
+ *     http://www.cse.yorku.ca/~oz/marsaglia-rng.html
+ *
+ *     We implement MWC here, which uses 2 32-bit numbers for a
+ *     state, and has a period of 2^60.
+ *
+ *     We could extend this to a larger RNG with 4 32-bit state
+ *     numbers {a, b, c, d} and use KISS, which has a period of about
+ *     2^123.
+ *
+ *     a' = 36969 * (a & 65535) + (a >> 16)
+ *     b' = 18000 * (b & 65535) + (b >> 16))
+ *
+ *     MWC     (a' << 16) + b'
+ *     SHR3    (c ^= (c <<17); c ^= ( c>>13); c ^= (c << 5))
+ *     CONG    d' = 69069 * d + 1234567
+ *     KISS    ((MWC^CONG)+SHR3)
+ */
 uint32_t fr_fast_rand(fr_fast_rand_t *ctx)
 {
        ctx->a = (36969 * (ctx->a & 0xffff)) + (ctx->a >> 16);