mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
hash.wyhash: implement rand function from wyhash original impl
This commit is contained in:
parent
7f709c3285
commit
7808f4c272
14
vlib/hash/wyhash/rand.v
Normal file
14
vlib/hash/wyhash/rand.v
Normal 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)
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user