mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
crypto.rand: fix rand test from failing sometimes
This commit is contained in:
parent
153c6d5416
commit
486b3d2f92
@ -30,14 +30,21 @@ fn test_crypto_rand_read() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_crypto_rand_int_u64() {
|
fn test_crypto_rand_int_u64() {
|
||||||
max := u64(200)
|
max := u64(160)
|
||||||
r1 := rand.int_u64(max) or {
|
mut unique := []int
|
||||||
|
for _ in 0..80 {
|
||||||
|
r := rand.int_u64(max) or {
|
||||||
assert false
|
assert false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r2 := rand.int_u64(max) or {
|
if r >= max {
|
||||||
assert false
|
assert false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
assert r1 > u64(0) && r2 > u64(0) && r1 < max && r2 < max
|
n := int(r)
|
||||||
|
if !(n in unique) {
|
||||||
|
unique << n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert unique.len >= 40
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user