2019-09-23 00:50:22 +03:00
|
|
|
|
|
|
|
import rand
|
|
|
|
import time
|
|
|
|
|
2020-04-08 17:28:12 +03:00
|
|
|
fn show_u64s(a []u64){
|
2020-04-26 14:49:31 +03:00
|
|
|
mut res := []string{}
|
2020-04-08 17:28:12 +03:00
|
|
|
for x in a {
|
|
|
|
res << x.str()
|
|
|
|
}
|
|
|
|
print('[')
|
|
|
|
print(res.join(', '))
|
|
|
|
println(']')
|
|
|
|
}
|
|
|
|
|
2019-09-23 00:50:22 +03:00
|
|
|
fn gen_randoms(seed i64, bound int) []u64 {
|
|
|
|
mut randoms := [u64(0)].repeat(20)
|
|
|
|
mut rnd := rand.new_splitmix64( u64(seed) )
|
|
|
|
for i in 0..20 {
|
|
|
|
randoms[i] = rnd.bounded_next(u64(bound))
|
|
|
|
}
|
|
|
|
return randoms
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_splitmix64_reproducibility() {
|
|
|
|
t := time.ticks()
|
|
|
|
println('t: $t')
|
|
|
|
randoms1 := gen_randoms(t, 1000)
|
|
|
|
randoms2 := gen_randoms(t, 1000)
|
|
|
|
assert randoms1.len == randoms2.len
|
2020-04-08 17:28:12 +03:00
|
|
|
show_u64s( randoms1 )
|
|
|
|
show_u64s( randoms2 )
|
2019-09-23 00:50:22 +03:00
|
|
|
len := randoms1.len
|
|
|
|
for i in 0..len {
|
|
|
|
assert randoms1[i] == randoms2[i]
|
2020-04-26 14:49:31 +03:00
|
|
|
}
|
2019-09-23 00:50:22 +03:00
|
|
|
}
|