Skip to main content

rl_lang/interpreter/stdlib/random/
mod.rs

1//! `std::random` - random number generation using a custom Xoshiro256** PRNG.
2//!
3//! The PRNG state is stored on [`Evaluator::rng`] and seeded from the system clock
4//! at startup. All random functions share this single instance.
5
6mod rand_bool;
7mod rand_bool_weighted;
8mod rand_float;
9mod rand_float_range;
10mod rand_int;
11mod rand_int_range;
12mod random_general;
13pub mod xoshiro;
14
15use crate::interpreter::native::Module;
16
17pub const KEYWORDS: &[&str] = &[
18    "rand_int",
19    "rand_int_range",
20    "rand_float",
21    "rand_float_range",
22    "rand_bool",
23    "rand_bool_weighted",
24    "rand_dice",
25    "rand_dices",
26    "rand_range",
27    "rand_range_step",
28    "rand_choice",
29    "rand_choices",
30    "rand_sample",
31    "rand_shuffle",
32    "rand_byte",
33    "rand_bytes",
34    "rand_char",
35    "rand_string",
36];
37
38pub fn module() -> Module {
39    Module::new("random")
40        .with_function("rand_int", rand_int::func)
41        .with_function("rand_int_range", rand_int_range::func)
42        .with_function("rand_float", rand_float::func)
43        .with_function("rand_float_range", rand_float_range::func)
44        .with_function("rand_bool_weighted", rand_bool_weighted::func)
45        .with_function("rand_bool", rand_bool::func)
46        .with_function("rand_dice", random_general::dice)
47        .with_function("rand_range", random_general::range)
48        .with_function("rand_range_step", random_general::range_step)
49        .with_function("rand_choice", random_general::choice)
50        .with_function("rand_choices", random_general::choices)
51        .with_function("rand_sample", random_general::sample)
52        .with_function("rand_shuffle", random_general::shuffle)
53        .with_function("rand_byte", random_general::byte)
54        .with_function("rand_bytes", random_general::bytes)
55        .with_function("rand_char", random_general::char)
56        .with_function("rand_string", random_general::string)
57        .with_function("rand_dices", random_general::dices)
58}