Skip to content

2.0.0

Choose a tag to compare

@aglitchman aglitchman released this 24 Feb 21:18
· 7 commits to main since this release

What's Changed

New API

  • splitmix64.toss() - Returns 0 or 1 (coin flip).
  • splitmix64.dice(roll, type) - Rolls one or more dice of the given type. Returns a table of individual rolls and the total sum. Dice types: splitmix64.D4, splitmix64.D6, splitmix64.D8, splitmix64.D10, splitmix64.D12, splitmix64.D20, splitmix64.D100.
  • splitmix64.randomchoice(t) - Returns a random element from array t. Raises an error if the array is empty.
  • splitmix64.weightedchoice(t) - Returns a random key from table t where values are weights. Keys are sorted deterministically (numbers first, then strings) for reproducibility. Raises an error if weights are invalid.
  • splitmix64.state() - Returns the current internal state as a string for save/restore or full 64-bit precision.
  • splitmix64.new_instance([seed]) - Creates a new RNG instance with isolated state. Optional seed (number or string) for reproducibility. Instance has the same methods as the global module: random, randomseed, state, randomchoice, weightedchoice, toss, dice.

Changes to Existing API

  • splitmix64.randomseed(x) - Now accepts number or string (decimal uint64) for full 64-bit precision. Lua doubles cannot represent all uint64 values.