MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / random_uniform

Function random_uniform

aiscript-vm/src/stdlib/random.rs:100–124  ·  view source on GitHub ↗
(
    _state: &mut State<'gc>,
    args: Vec<Value<'gc>>,
)

Source from the content-addressed store, hash-verified

98}
99
100fn random_uniform<'gc>(
101 _state: &mut State<'gc>,
102 args: Vec<Value<'gc>>,
103) -> Result<Value<'gc>, VmError> {
104 if args.len() != 2 {
105 return Err(VmError::RuntimeError(
106 "uniform() takes exactly 2 arguments: min and max".into(),
107 ));
108 }
109
110 let min = float_arg!(&args, 0, "uniform")?;
111 let max = float_arg!(&args, 1, "uniform")?;
112
113 if min > max {
114 return Err(VmError::RuntimeError(
115 "uniform(): max must be greater than min".into(),
116 ));
117 }
118
119 RNG.with(|rng| {
120 let dist = Uniform::new(min, max).unwrap();
121 let val = dist.sample(&mut *rng.borrow_mut());
122 Ok(Value::Number(val))
123 })
124}
125
126fn random_range<'gc>(
127 _state: &mut State<'gc>,

Callers

nothing calls this directly

Calls 3

RuntimeErrorClass · 0.85
lenMethod · 0.80
borrow_mutMethod · 0.45

Tested by

no test coverage detected