MCPcopy Create free account
hub / github.com/5ocworkshop/bgraph / random_range

Function random_range

examples/demo/fnc_random_range.rs:15–27  ·  view source on GitHub ↗

Generate a random f32 in the range [min, max]. Uses a simple LCG algorithm. Thread-unsafe (uses static mut).

(min: f32, max: f32)

Source from the content-addressed store, hash-verified

13///
14/// Uses a simple LCG algorithm. Thread-unsafe (uses static mut).
15pub 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>

Callers 4

update_cpuMethod · 0.85
update_networkMethod · 0.85
update_memoryMethod · 0.85
update_btopMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected