RandomGenerator
A source of random numbers of its own that you can save and repeat, which you create with math3d.random_generator.
A source of random numbers of its own that you can save and repeat, which you create with math3d.random_generator.
Gives a random number from 0 up to 1, or from min to max if you give both.
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.Gives a random whole number from min to max, with both ends included.
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.Gives a random item from a list, where every item is as likely as the others.
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.Picks an item from a list, where a bigger weight makes it come up more often.
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.Puts a list in random order, changing that same list instead of making a copy.
rng:shuffle(deck)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.Gives text you can save, so a new generator can carry on the same draws later.
profile:set("gacha.rng", rng:state())Use it forsaving a generator's progress in a player's Profile.