From 486b3d2f925f4966398089c01ab8998c9550534a Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Thu, 19 Sep 2019 20:12:40 +1000 Subject: [PATCH] crypto.rand: fix rand test from failing sometimes --- vlib/crypto/rand/rand_test.v | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/vlib/crypto/rand/rand_test.v b/vlib/crypto/rand/rand_test.v index b1edad268d..066804a82f 100644 --- a/vlib/crypto/rand/rand_test.v +++ b/vlib/crypto/rand/rand_test.v @@ -30,14 +30,21 @@ fn test_crypto_rand_read() { } fn test_crypto_rand_int_u64() { - max := u64(200) - r1 := rand.int_u64(max) or { - assert false - return + max := u64(160) + mut unique := []int + for _ in 0..80 { + r := rand.int_u64(max) or { + assert false + return + } + if r >= max { + assert false + return + } + n := int(r) + if !(n in unique) { + unique << n + } } - r2 := rand.int_u64(max) or { - assert false - return - } - assert r1 > u64(0) && r2 > u64(0) && r1 < max && r2 < max + assert unique.len >= 40 }