1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

rand: fix edge case, when bit length is 31 and 63, add tests for rand.intn(2147483647)! etc (#18714)

This commit is contained in:
Subhomoy Haldar
2023-06-29 20:11:27 +01:00
committed by GitHub
parent cf323cd0ef
commit 7ab11097be
2 changed files with 32 additions and 4 deletions

View File

@ -454,3 +454,23 @@ fn test_element2() {
assert 4 != e
}
}
fn test_proper_masking() {
under32 := []int{len: 10, init: index * 0 + rand.intn(1073741823)!}
assert under32 != [0].repeat(10)
over32 := []int{len: 10, init: index * 0 + rand.intn(1073741824)!}
assert over32 != [0].repeat(10)
under64 := []i64{len: 10, init: index * 0 + rand.i64n(i64(4611686018427387903))!}
assert under64 != [i64(0)].repeat(10)
over64 := []i64{len: 10, init: index * 0 + rand.i64n(i64(4611686018427387904))!}
assert over64 != [i64(0)].repeat(10)
almost_full32 := []int{len: 10, init: index * 0 + rand.intn(2147483647)!}
assert almost_full32 != [0].repeat(10)
almost_full64 := []i64{len: 10, init: index * 0 + rand.i64n(i64(9223372036854775807))!}
assert almost_full64 != [i64(0)].repeat(10)
}