1use std::ops::{Bound, RangeBounds};
6
7pub fn random_seed() {
11 unsafe { lotus_script_sys::rand::random_seed() }
12}
13
14pub fn seed(seed: u64) {
18 unsafe { lotus_script_sys::rand::seed(seed) }
19}
20
21pub fn gen_f64() -> f64 {
25 unsafe { lotus_script_sys::rand::f64() }
26}
27
28pub fn gen_u64(range: impl RangeBounds<u64>) -> u64 {
32 let min = match range.start_bound() {
33 Bound::Included(min) => *min,
34 Bound::Excluded(min) => min + 1,
35 Bound::Unbounded => 0,
36 };
37
38 let max = match range.end_bound() {
39 Bound::Included(max) => *max,
40 Bound::Excluded(max) => max - 1,
41 Bound::Unbounded => u64::MAX,
42 };
43
44 assert!(min <= max, "min must be less than or equal to max");
45
46 unsafe { lotus_script_sys::rand::u64(min, max) }
47}