(_state: &mut State<'gc>, args: Vec<Value<'gc>>)
| 75 | } |
| 76 | |
| 77 | fn random_int<'gc>(_state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> { |
| 78 | if args.len() != 2 { |
| 79 | return Err(VmError::RuntimeError( |
| 80 | "randint() takes exactly 2 arguments: min and max".into(), |
| 81 | )); |
| 82 | } |
| 83 | |
| 84 | let min = float_arg!(&args, 0, "randint")? as i64; |
| 85 | let max = float_arg!(&args, 1, "randint")? as i64; |
| 86 | |
| 87 | if min > max { |
| 88 | return Err(VmError::RuntimeError( |
| 89 | "randint(): max must be greater than min".into(), |
| 90 | )); |
| 91 | } |
| 92 | |
| 93 | RNG.with(|rng| { |
| 94 | let dist = Uniform::new_inclusive(min, max).unwrap(); |
| 95 | let val = dist.sample(&mut *rng.borrow_mut()); |
| 96 | Ok(Value::Number(val as f64)) |
| 97 | }) |
| 98 | } |
| 99 | |
| 100 | fn random_uniform<'gc>( |
| 101 | _state: &mut State<'gc>, |
nothing calls this directly
no test coverage detected