From 16f6261b445823061977147917e406bbd6e6e779 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 10 Nov 2019 17:44:59 -0600 Subject: [PATCH] Improve randomness of numbers from new rng. First few numbers are very biased. --- src/core/math.c | 2 ++ test/suite7.janet | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/math.c b/src/core/math.c index f6081e48..a1f1f605 100644 --- a/src/core/math.c +++ b/src/core/math.c @@ -70,6 +70,8 @@ void janet_rng_seed(JanetRNG *rng, uint32_t seed) { rng->c = 0x17af0931u; rng->d = 0xFFFaaFFFu; rng->counter = 0u; + /* First several numbers aren't that random. */ + for (int i = 0; i < 16; i++) janet_rng_u32(rng); } uint32_t janet_rng_u32(JanetRNG *rng) { diff --git a/test/suite7.janet b/test/suite7.janet index 500d8d91..4234b722 100644 --- a/test/suite7.janet +++ b/test/suite7.janet @@ -226,6 +226,7 @@ (with-dyns [:out @""] (prin "abcd") (prin (dyn :out)) - (assert (deep= (dyn :out) @"abcdabcd") "print buffer to self")) + (prin (dyn :out)) + (assert (deep= (dyn :out) @"abcdabcdabcdabcd") "print buffer to self")) (end-suite)