mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
rand: move constants from rand.util to a new module rand.constants (#8408)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
module splitmix64
|
||||
|
||||
import rand.seed
|
||||
import rand.util
|
||||
import rand.constants
|
||||
|
||||
// SplitMix64RNG ported from http://xoshiro.di.unimi.it/splitmix64.c
|
||||
pub struct SplitMix64RNG {
|
||||
@@ -33,7 +33,7 @@ pub fn (mut rng SplitMix64RNG) u32() u32 {
|
||||
return rng.extra
|
||||
}
|
||||
full_value := rng.u64()
|
||||
lower := u32(full_value & util.lower_mask)
|
||||
lower := u32(full_value & constants.lower_mask)
|
||||
upper := u32(full_value >> 32)
|
||||
rng.extra = upper
|
||||
rng.has_extra = true
|
||||
@@ -122,13 +122,13 @@ pub fn (mut rng SplitMix64RNG) i64() i64 {
|
||||
// int31 returns a positive pseudorandom 31-bit `int`.
|
||||
[inline]
|
||||
pub fn (mut rng SplitMix64RNG) int31() int {
|
||||
return int(rng.u32() & util.u31_mask) // Set the 32nd bit to 0.
|
||||
return int(rng.u32() & constants.u31_mask) // Set the 32nd bit to 0.
|
||||
}
|
||||
|
||||
// int63 returns a positive pseudorandom 63-bit `i64`.
|
||||
[inline]
|
||||
pub fn (mut rng SplitMix64RNG) int63() i64 {
|
||||
return i64(rng.u64() & util.u63_mask) // Set the 64th bit to 0.
|
||||
return i64(rng.u64() & constants.u63_mask) // Set the 64th bit to 0.
|
||||
}
|
||||
|
||||
// intn returns a pseudorandom `int` in range `[0, max)`.
|
||||
@@ -175,13 +175,13 @@ pub fn (mut rng SplitMix64RNG) i64_in_range(min i64, max i64) i64 {
|
||||
// f32 returns a pseudorandom `f32` value in range `[0, 1)`.
|
||||
[inline]
|
||||
pub fn (mut rng SplitMix64RNG) f32() f32 {
|
||||
return f32(rng.u32()) / util.max_u32_as_f32
|
||||
return f32(rng.u32()) / constants.max_u32_as_f32
|
||||
}
|
||||
|
||||
// f64 returns a pseudorandom `f64` value in range `[0, 1)`.
|
||||
[inline]
|
||||
pub fn (mut rng SplitMix64RNG) f64() f64 {
|
||||
return f64(rng.u64()) / util.max_u64_as_f64
|
||||
return f64(rng.u64()) / constants.max_u64_as_f64
|
||||
}
|
||||
|
||||
// f32n returns a pseudorandom `f32` value in range `[0, max)`.
|
||||
|
Reference in New Issue
Block a user