math
Functions
imod(index : integer
, length : integer
)
->
integer
Wrap a lua 1 based integer index into the given array/table length.
->
(index - 1) % length + 1
random(m : integer
, n : integer
)
->
integer
math.random()
: Returns a float in the range [0,1).math.random(n)
: Returns a integer in the range [1, n].math.random(m, n)
: Returns a integer in the range [m, n].
randomseed(x : integer
)
math.randomseed(x, y)
: Concatenatex
andy
into a 128-bitseed
to reinitialize the pseudo-random generator.math.randomseed(x)
: Equate tomath.randomseed(x, 0)
.math.randomseed()
: Generates a seed with a weak attempt for randomness.
randomstate(seed : integer
?
)
->
(m : integer
?
, n : integer
?
) ->
number
Create a new local random number state with the given optional seed value.
When no seed value is specified, the global
math.randomseed
value is used. When no global seed value is available, a new unique random seed is created.Random states can be useful to create multiple, separate seeded random number generators, e.g. in pattern, gate or emit generators, which get reset with the generator functions.
examples:
return rhythm { emit = function(init_context) -- use a unique random sequence every time the rhythm gets (re)triggered local rand = math.randomstate(12345) return function(context) if rand(1, 10) > 5 then return "c5" else return "g4" end end }
See:
- math.random function arguments
- math.randomseed seeding