(ctx: Context)
| 9 | }; |
| 10 | |
| 11 | pub 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 | |
| 39 | thread_local! { |
| 40 | static RNG: std::cell::RefCell<StdRng> = std::cell::RefCell::new( |
no test coverage detected