Macro obfstr::random [−][src]
Compiletime random number generator.
Supported types are u8
, u16
, u32
, u64
, usize
, i8
, i16
, i32
, i64
, isize
, bool
, f32
and f64
.
The integer types generate a random value in their respective range.
The float types generate a random value in range of [1.0, 2.0)
.
While the result is generated at compiletime only the integer types are available in const contexts.
Note that the seed must be a uniformly distributed random u64
value.
If such a value is not available, see the splitmix
function to generate it from non uniform random value.
const RND: i32 = obfstr::random!(u8) as i32; assert!(RND >= 0 && RND <= 255);
The random machinery is robust enough that it avoids exact randomness when mixed with other macros:
assert_ne!(obfstr::random!(u64), obfstr::random!(u64));