HomeIndex

Random Numbers

random(start,end)
Returns a random number between start and end inclusively.
If both start and end are int values the number returned will also be an int. If start or end are float values then the number returned will be a random float.
local n = random(1, 100) // Could be 56 local f = random(0.0, 1.0) // Could be 0.675
randomseed(seed) | randomseed()
Seeds the random number generator with 'seed' or returns the current seed
if seed is null the random number generator is randomly seeded based on time and other factors.
Using randomseed() with no parameter will return the current seed.
randomseed(42) local v = randomseed() print(v) // 42
randomodds(odds)
Returns true or false based on the odds
if (randomodds(0.50)) { print("heads") } else { print("tails") }
randomfrom(array|table) | randomfrom(item, item, ...)
Returns a random element from a table or array or a item from a list.
local n = randomfrom("face_front", "face_right", "face_left") local a = [100,200,300] local n = randomfrom(a)