(
_state: &mut State<'gc>,
args: Vec<Value<'gc>>,
)
| 98 | } |
| 99 | |
| 100 | fn 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 | |
| 126 | fn random_range<'gc>( |
| 127 | _state: &mut State<'gc>, |
nothing calls this directly
no test coverage detected