comcode-org / hackmud_wiki

https://wiki.hackmud.com/
Other
12 stars 21 forks source link

scripts.lib RNG usage examples are not clear #450

Closed tukib closed 2 months ago

tukib commented 2 months ago

Problem

The examples for the scripts.lib RNG methods do not show how to generate a random value.

Context

Affects:

LCG current:

function(context, args) {
  const l = #fs.scripts.lib();
  my_seed = 12345;

  return l.LCG(my_seed);
}

LCG example improvement:

function(context, args) {
  const l = #fs.scripts.lib();
  const seed = 12345;
  const rng = l.LCG(seed);
  const random_value = Math.floor(rng() * 10) // random value from 0 (inclusive) to 10 (exclusive)
  return random_value
}