use std::time::{SystemTime, UNIX_EPOCH};
pub fn random_init() {
unsafe {
libc::srand(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u32);
libc::rand();
};
}
pub fn random_max_int() -> i32 {
libc::RAND_MAX
}
pub fn random_int() -> i32 {
unsafe { libc::rand() }
}
pub fn random_int_range(min: i32, max: i32) -> i32 {
unsafe { min + (libc::rand() % (max - min)) }
}
pub fn random_float() -> f32 {
unsafe { libc::rand() as f32 / libc::RAND_MAX as f32 }
}
pub fn random_float_range(min: f32, max: f32) -> f32 {
unsafe { min + libc::rand() as f32 / libc::RAND_MAX as f32 * (max - min) }
}
pub fn random_double() -> f64 {
unsafe { libc::rand() as f64 / libc::RAND_MAX as f64 }
}
pub fn random_double_range(min: f64, max: f64) -> f64 {
unsafe { min + libc::rand() as f64 / libc::RAND_MAX as f64 * (max - min) }
}