1use std::cell::Cell;
2
3pub const INFINITY: f64 = f64::INFINITY;
5pub const PI: f64 = std::f64::consts::PI;
7
8pub fn degrees_to_radians(degrees: f64) -> f64 {
10 degrees * PI / 180.0
11}
12
13thread_local! {
15 static RNG_STATE: Cell<u64> = Cell::new(0x123456789abcdef0);
16}
17
18pub fn random_double() -> f64 {
20 RNG_STATE.with(|state| {
21 let mut s = state.get();
22 s ^= s << 13;
23 s ^= s >> 7;
24 s ^= s << 17;
25 state.set(s);
26 (s >> 11) as f64 * (1.0 / (1u64 << 53) as f64)
27 })
28}
29
30pub fn random_double_range(min: f64, max: f64) -> f64 {
32 min + (max - min) * random_double()
33}