RandomGenerator
A source of random numbers of its own that you can save and repeat, which you create with math3d.random_generator.
RandomGenerator:number
method#Gives a random number from 0 up to 1, or from min to max if you give both.
example
local speed = rng:number(10, 20)
Use it forpicking a random drop height for a loot crate so each one falls differently.
minoptionalThe lowest value. Give both min and max, or neither for 0 up to 1.
maxoptionalThe highest value.
RandomGenerator:integer
method#Gives a random whole number from min to max, with both ends included.
example
local roll = rng:integer(1, 6)
Use it forrolling a dice in a board game, or picking which door hides the prize.
minThe lowest whole number, from -2^53.
maxThe highest whole number, up to 2^53.
RandomGenerator:pick
method#Gives a random item from a list, where every item is as likely as the others.
example
local prize = rng:pick({ "sword", "shield", "potion" })
Use it forchoosing a random prize from a treasure chest, out of a list of possible rewards.
listA list with at least one item.
RandomGenerator:weighted
method#Picks an item from a list, where a bigger weight makes it come up more often.
RandomGenerator:weighted(entries: { { item: any, weight: number } }) -> (any, number)
example
local rarity = rng:weighted({ { item = "SSR", weight = 3 }, { item = "SR", weight = 18.5 }, { item = "R", weight = 78.5 } })
Use it forloot tables where rare items drop less often than common ones.
entriesA list of { item = …, weight = … } entries. Weights are finite numbers of at least 0, and at least one is above 0.
RandomGenerator:shuffle
method#Puts a list in random order, changing that same list instead of making a copy.
Use it forshuffling a deck of cards, or the order of the minigames in a round.
listThe list to put in random order, in place.
RandomGenerator:state
method#Gives text you can save, so a new generator can carry on the same draws later.
example
profile:set("gacha.rng", rng:state())
Use it forsaving a generator's progress in a player's Profile.