1use std::ops::{Bound, RangeBounds};
3
4pub fn random_seed() {
6 unsafe { lotus_script_sys::rand::random_seed() }
7}
8
9pub fn seed(seed: u64) {
11 unsafe { lotus_script_sys::rand::seed(seed) }
12}
13
14pub fn gen_f64() -> f64 {
16 unsafe { lotus_script_sys::rand::f64() }
17}
18
19pub fn gen_u64(range: impl RangeBounds<u64>) -> u64 {
21 let min = match range.start_bound() {
22 Bound::Included(min) => *min,
23 Bound::Excluded(min) => min + 1,
24 Bound::Unbounded => 0,
25 };
26
27 let max = match range.end_bound() {
28 Bound::Included(max) => *max,
29 Bound::Excluded(max) => max - 1,
30 Bound::Unbounded => u64::MAX,
31 };
32
33 assert!(min <= max, "min must be less than or equal to max");
34
35 unsafe { lotus_script_sys::rand::u64(min, max) }
36}