Generate a random f32 in the range [min, max]. Uses a simple LCG algorithm. Thread-unsafe (uses static mut).
(min: f32, max: f32)
| 13 | /// |
| 14 | /// Uses a simple LCG algorithm. Thread-unsafe (uses static mut). |
| 15 | pub fn random_range(min: f32, max: f32) -> f32 { |
| 16 | unsafe { |
| 17 | SEED = SEED.wrapping_mul(6364136223846793005).wrapping_add(1); |
| 18 | if SEED == 0 { |
| 19 | SEED = SystemTime::now() |
| 20 | .duration_since(UNIX_EPOCH) |
| 21 | .unwrap() |
| 22 | .as_nanos() as u64; |
| 23 | } |
| 24 | let t = ((SEED >> 33) as f32) / (u32::MAX as f32); |
| 25 | min + t * (max - min) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | // <FILE>examples/demo/fnc_random_range.rs</FILE> - <DESC>Simple random number generator</DESC> |
| 30 | // <VERS>END OF VERSION: 1.0.0</VERS> |
no outgoing calls
no test coverage detected