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

Function random_seed

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

Source from the content-addressed store, hash-verified

43}
44
45fn random_seed<'gc>(_state: &mut State<'gc>, args: Vec<Value<'gc>>) -> Result<Value<'gc>, VmError> {
46 let seed = if args.is_empty() {
47 // Use current time as seed if none provided
48 SystemTime::now()
49 .duration_since(SystemTime::UNIX_EPOCH)
50 .unwrap()
51 .as_secs()
52 } else {
53 float_arg!(&args, 0, "seed")? as u64
54 };
55
56 RNG.with(|rng| {
57 *rng.borrow_mut() = StdRng::seed_from_u64(seed);
58 });
59
60 Ok(Value::Number(seed as f64))
61}
62
63fn random_float<'gc>(
64 _state: &mut State<'gc>,

Callers

nothing calls this directly

Calls 1

borrow_mutMethod · 0.45

Tested by

no test coverage detected