From dd00c798611bccea4bf167059a7d0f7bd5ffc1ce Mon Sep 17 00:00:00 2001 From: div72 <60045611+div72@users.noreply.github.com> Date: Wed, 21 Apr 2021 12:20:55 +0300 Subject: [PATCH] rand: fix wrong function signature (#9808) --- vlib/rand/pcg32/pcg32.v | 2 +- vlib/rand/pcg32/pcg32_test.v | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/vlib/rand/pcg32/pcg32.v b/vlib/rand/pcg32/pcg32.v index 1e486d6035..25a83f7f74 100644 --- a/vlib/rand/pcg32/pcg32.v +++ b/vlib/rand/pcg32/pcg32.v @@ -91,7 +91,7 @@ pub fn (mut rng PCG32RNG) u64n(max u64) u64 { // u32_in_range returns a pseudorandom 32-bit unsigned `u32` in range `[min, max)`. [inline] -pub fn (mut rng PCG32RNG) u32_in_range(min u64, max u64) u64 { +pub fn (mut rng PCG32RNG) u32_in_range(min u32, max u32) u32 { if max <= min { eprintln('max must be greater than min') exit(1) diff --git a/vlib/rand/pcg32/pcg32_test.v b/vlib/rand/pcg32/pcg32_test.v index c0a1334d49..17048a02cf 100644 --- a/vlib/rand/pcg32/pcg32_test.v +++ b/vlib/rand/pcg32/pcg32_test.v @@ -1,4 +1,5 @@ import math +import rand import rand.pcg32 import rand.seed @@ -141,13 +142,13 @@ fn test_pcg32_u64n() { } fn test_pcg32_u32_in_range() { - max := u64(484468466) - min := u64(316846) + max := u32(484468466) + min := u32(316846) for seed in seeds { mut rng := pcg32.PCG32RNG{} rng.seed(seed) for _ in 0 .. range_limit { - value := rng.u32_in_range(u64(min), u64(max)) + value := rng.u32_in_range(u32(min), u32(max)) assert value >= min assert value < max } @@ -330,3 +331,7 @@ fn test_pcg32_f64_in_range() { } } } + +fn test_change_default_random_generator() { + rand.set_rng(pcg32.PCG32RNG{}) +}