diff --git a/vlib/hash/wyhash/rand.v b/vlib/hash/wyhash/rand.v new file mode 100644 index 0000000000..3f6e9a86b6 --- /dev/null +++ b/vlib/hash/wyhash/rand.v @@ -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) + } +} diff --git a/vlib/hash/wyhash/wyhash_test.v b/vlib/hash/wyhash/wyhash_test.v index 1d7bd3b675..414b05dce5 100644 --- a/vlib/hash/wyhash/wyhash_test.v +++ b/vlib/hash/wyhash/wyhash_test.v @@ -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 + } +} \ No newline at end of file