Skip to content

TableRandomizer

Hyomoto edited this page Jun 24, 2021 · 1 revision
Jump To Go Back Arguments Methods Variables

TableRandomizer( seed, table )

Implements: Randomizer

Uses a pre-defined table of lookup values to return random numbers. This can be helpful if you wish to weight certain numbers, but has the drawback of requiring an array the size of the table. Each time a random number is drawn, the pointer in the table advances to the next one and returns the value stored there. You may provide your own table of numbers, or have one generated.

Output: A randomizer that contains a table of 256 values.

Arguments

Name Type Purpose
seed int The starting seed for this randomizer. If you are generating a table, this seed is used to generate the table instead.
table array The table of numbers to use.

Methods

Jump To top next generate from_array

next( )

Returns: int

Name Type Purpose
None

Returns the next number in the table. If the last number has been read, the read position will return to the start of the table.


generate( size, *rand )

Returns: self

Throws: InvalidArgumentType

Name Type Purpose
size int The size of the table
*rand Randomizer optional: If specified, will be used instead of GMS' functions

Populates a new table of size elements using seed. The table will contain each number 0 to size - 1 inclusive. If size is not a number or is less than 1, or rand is not a Randomizer, InvalidArgumentType will be thrown.


from_array( array )

Returns: self

Throws: InvalidArgumentType

Name Type Purpose
array array The array of values

Sets the table of values used to return numbers. If an array is not provided, InvalidArgumentType will be thrown.


Variables

Jump To top
Name Type Initial Purpose
__Table array undefined The table used to look up numbers
Clone this wiki locally