hash.wyhash: implement rand function from wyhash original impl

pull/3635/head
joe-conigliaro 2020-02-03 16:02:28 +11:00 committed by GitHub
parent 7f709c3285
commit 7808f4c272
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,14 @@
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module wyhash
pub fn rand_u64(seed &u64) u64 {
mut seed0 := seed
unsafe{
mut seed1 := *seed0
seed1+=wyp0
*seed0 = seed1
return wymum(seed1^wyp1, seed1)
}
}

View File

@ -27,3 +27,15 @@ fn test_wyhash() {
assert got == test.expected
}
}
fn test_rand_u64() {
seed := u64(111)
mut rand_nos := []u64
for _ in 0..40 {
rand_no := wyhash.rand_u64(&seed)
for r in rand_nos {
assert rand_no != r
}
rand_nos << rand_no
}
}