Lua API

Rand module

Functions for working with randomness.

Usage

local Rand = ELONA.require("core.Rand")

Functions

rnd (n) Returns a random number from 0 to n, exclusive.
rnd_capped (n) Returns a random number from 0 to min(n, 32768), exclusive.
one_in (n) Returns true one out of every n times.
coinflip () Returns true 50% of the time.
between (min, max) Returns a random number from min to max, exclusive.
choice (table) Returns a random object from a table.

Functions

# rnd (n)

Returns a random number from 0 to n, exclusive.

Parameters:
  • n : (num)
Returns:
  • (num) a number in [0, n)
# rnd_capped (n)

Returns a random number from 0 to min(n, 32768), exclusive.

It emulates vanilla's random number generation, capped by the upper limit.

Parameters:
  • n : (num)
Returns:
  • (num) a number in [0, min(n, 32768))
# one_in (n)

Returns true one out of every n times.

Parameters:
  • n : (num)
Returns:
  • (bool) true one out of every n times
# coinflip ()

Returns true 50% of the time.

Returns:
  • (bool) true 50% of the time
# between (min, max)

Returns a random number from min to max, exclusive.

Parameters:
  • min : (num)
  • max : (num)
Returns:
  • (num) a number in [min, max)
# choice (table)

Returns a random object from a table.

Parameters:
  • table : (table) a table
Returns:
  • (object) an object from the table