2022-05-22 13:21:52 +03:00
|
|
|
// Copyright (c) 2019-2022 Alexander Medvednikov. All rights reserved.
|
|
|
|
// Use of this source code is governed by an MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
2021-08-18 11:33:37 +03:00
|
|
|
module config
|
|
|
|
|
|
|
|
import rand.seed
|
|
|
|
|
|
|
|
// PRNGConfigStruct is a configuration struct for creating a new instance of the default RNG.
|
|
|
|
// Note that the RNGs may have a different number of u32s required for seeding. The default
|
|
|
|
// generator WyRand used 64 bits, ie. 2 u32s so that is the default. In case your desired generator
|
|
|
|
// uses a different number of u32s, use the `seed.time_seed_array()` method with the correct
|
|
|
|
// number of u32s.
|
2021-09-14 00:05:30 +03:00
|
|
|
[params]
|
2021-08-18 11:33:37 +03:00
|
|
|
pub struct PRNGConfigStruct {
|
|
|
|
pub:
|
|
|
|
seed_ []u32 = seed.time_seed_array(2)
|
|
|
|
}
|
2022-05-22 13:21:52 +03:00
|
|
|
|
|
|
|
// Configuration struct for generating normally distributed floats. The default value for
|
|
|
|
// `mu` is 0 and the default value for `sigma` is 1.
|
|
|
|
[params]
|
|
|
|
pub struct NormalConfigStruct {
|
|
|
|
pub:
|
|
|
|
mu f64 = 0.0
|
|
|
|
sigma f64 = 1.0
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configuration struct for the shuffle functions.
|
|
|
|
// The start index is inclusive and the end index is exclusive.
|
|
|
|
// Set the end to 0 to shuffle until the end of the array.
|
|
|
|
[params]
|
|
|
|
pub struct ShuffleConfigStruct {
|
|
|
|
pub:
|
|
|
|
start int
|
|
|
|
end int
|
|
|
|
}
|
|
|
|
|
|
|
|
// validate_for is a helper function for validating the configuration struct for the given array.
|
2022-11-26 19:23:26 +03:00
|
|
|
pub fn (config ShuffleConfigStruct) validate_for[T](a []T) ! {
|
2022-05-22 13:21:52 +03:00
|
|
|
if config.start < 0 || config.start >= a.len {
|
|
|
|
return error("argument 'config.start' must be in range [0, a.len)")
|
|
|
|
}
|
|
|
|
if config.end < 0 || config.end > a.len {
|
|
|
|
return error("argument 'config.end' must be in range [0, a.len]")
|
|
|
|
}
|
|
|
|
if config.end != 0 && config.end <= config.start {
|
|
|
|
return error("argument 'config.end' must be greater than 'config.start'")
|
|
|
|
}
|
|
|
|
}
|