2019-09-22 23:50:22 +02:00
|
|
|
|
|
|
|
import rand
|
|
|
|
import time
|
|
|
|
|
2020-04-08 16:28:12 +02:00
|
|
|
fn show_u64s(a []u64){
|
2020-04-26 13:49:31 +02:00
|
|
|
mut res := []string{}
|
2020-04-08 16:28:12 +02:00
|
|
|
for x in a {
|
|
|
|
res << x.str()
|
|
|
|
}
|
|
|
|
print('[')
|
|
|
|
print(res.join(', '))
|
|
|
|
println(']')
|
|
|
|
}
|
|
|
|
|
2019-09-22 23:50:22 +02: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 16:28:12 +02:00
|
|
|
show_u64s( randoms1 )
|
|
|
|
show_u64s( randoms2 )
|
2019-09-22 23:50:22 +02:00
|
|
|
len := randoms1.len
|
|
|
|
for i in 0..len {
|
|
|
|
assert randoms1[i] == randoms2[i]
|
2020-04-26 13:49:31 +02:00
|
|
|
}
|
2019-09-22 23:50:22 +02:00
|
|
|
}
|