rand: fix wrong function signature (#9808)
parent
51258923d7
commit
dd00c79861
|
@ -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)`.
|
// u32_in_range returns a pseudorandom 32-bit unsigned `u32` in range `[min, max)`.
|
||||||
[inline]
|
[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 {
|
if max <= min {
|
||||||
eprintln('max must be greater than min')
|
eprintln('max must be greater than min')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import math
|
import math
|
||||||
|
import rand
|
||||||
import rand.pcg32
|
import rand.pcg32
|
||||||
import rand.seed
|
import rand.seed
|
||||||
|
|
||||||
|
@ -141,13 +142,13 @@ fn test_pcg32_u64n() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pcg32_u32_in_range() {
|
fn test_pcg32_u32_in_range() {
|
||||||
max := u64(484468466)
|
max := u32(484468466)
|
||||||
min := u64(316846)
|
min := u32(316846)
|
||||||
for seed in seeds {
|
for seed in seeds {
|
||||||
mut rng := pcg32.PCG32RNG{}
|
mut rng := pcg32.PCG32RNG{}
|
||||||
rng.seed(seed)
|
rng.seed(seed)
|
||||||
for _ in 0 .. range_limit {
|
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 >= min
|
||||||
assert value < max
|
assert value < max
|
||||||
}
|
}
|
||||||
|
@ -330,3 +331,7 @@ fn test_pcg32_f64_in_range() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_change_default_random_generator() {
|
||||||
|
rand.set_rng(pcg32.PCG32RNG{})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue