Skip to content

Rand.lua

Functions


rand.new

rand.new(seed: number): LibLevelGen.Rng

Create a new random number generator instance.

Parameters:

Name Type Description
seed number Initial seed

Returns: LibLevelGen.Rng

Classes


LibLevelGen.Rng

Helper class for generating random numbers given a starting seed.

Methods:


LibLevelGen.Rng.rand

rand(self: LibLevelGen.Rng): number

Generate a random 32-bit integer number.

Parameters:

Name Type Description
self LibLevelGen.Rng The RNG instance

Returns: number


LibLevelGen.Rng.randFloatRange

randFloatRange(self: LibLevelGen.Rng, min: number, max: number): number

Generate a random float within the given range.

Parameters:

Name Type Description
self LibLevelGen.Rng The RNG instance
min number Minimum value
max number Maximum value

Returns: number


LibLevelGen.Rng.randIntRange

randIntRange(self: LibLevelGen.Rng, min: number, max: number): number

Generate a random integer within the given range.

Parameters:

Name Type Description
self LibLevelGen.Rng The RNG instance
min number Minimum value (inclusive)
max number Maximum value (not inclusive)

Returns: number


LibLevelGen.Rng.randChoice

randChoice(self: LibLevelGen.Rng, t: T[], remove?: boolean): T

Choose a random element from the given table.

Parameters:

Name Type Description
self LibLevelGen.Rng The RNG instance
t T[] Elements to choose from
remove? boolean If true, element will be removed from the original table.

Returns: T


LibLevelGen.Rng.randChoiceMany

randChoiceMany(self: LibLevelGen.Rng, choices: T[], n: number, remove: boolean): T

Choose a n elements from the given table.

Parameters:

Name Type Description
self LibLevelGen.Rng The RNG instance
choices T[] Elements to choose from
n number Number of elements to choose
remove boolean If true, element will be removed from the original table.

Returns: T


LibLevelGen.Rng.randChance

randChance(self: LibLevelGen.Rng, probability: number): boolean

Randomly returns boolean based on given probability.

Parameters:

Name Type Description
self LibLevelGen.Rng The RNG instance
probability number Value between 0.0 and 1.0

Returns: boolean


LibLevelGen.Rng.randWeightedChoice

randWeightedChoice(self: LibLevelGen.Rng, chances: table<string,number>): string

Randomly choose a value from the weighted choice data.

Parameters:

Name Type Description
self LibLevelGen.Rng The RNG instance
chances table<string,number> Mapping of values that can be chosen to their probability (does not have to add up to 1)

Returns: string