MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / create_random_module

Function create_random_module

aiscript-vm/src/stdlib/random.rs:11–37  ·  view source on GitHub ↗
(ctx: Context)

Source from the content-addressed store, hash-verified

9};
10
11pub fn create_random_module(ctx: Context) -> ModuleKind {
12 let name = ctx.intern(b"std.random");
13
14 let exports = [
15 // Core random functions
16 ("seed", Value::NativeFunction(NativeFn(random_seed))),
17 ("random", Value::NativeFunction(NativeFn(random_float))),
18 ("randint", Value::NativeFunction(NativeFn(random_int))),
19 ("uniform", Value::NativeFunction(NativeFn(random_uniform))),
20 // Range functions
21 ("range", Value::NativeFunction(NativeFn(random_range))),
22 ("choice", Value::NativeFunction(NativeFn(random_choice))),
23 // Distribution functions
24 ("normal", Value::NativeFunction(NativeFn(random_normal))),
25 (
26 "exponential",
27 Value::NativeFunction(NativeFn(random_exponential)),
28 ),
29 // Boolean function
30 ("bool", Value::NativeFunction(NativeFn(random_bool))),
31 ]
32 .into_iter()
33 .map(|(name, f)| (ctx.intern_static(name), f))
34 .collect();
35
36 ModuleKind::Native { name, exports }
37}
38
39thread_local! {
40 static RNG: std::cell::RefCell<StdRng> = std::cell::RefCell::new(

Callers 1

init_stdlibMethod · 0.85

Calls 3

NativeFnClass · 0.85
internMethod · 0.45
intern_staticMethod · 0.45

Tested by

no test coverage detected