Cauldron2D.GameMaker.Random (Cauldron2D.GameMaker v0.2.1)

Copy Markdown View Source

GameMaker's random numbers: the runtime's WELL512a generator, seeded as random_set_seed seeds it, giving what random, random_range, irandom, irandom_range and choose give.

random = Random.new(1234)
{value, random} = Random.random(random, 10)

A seed fills every one of the sixteen words of state with (seed × 0x343FD + 0x269EC3) >> 16 and starts at word 0. Each draw is one 32-bit output; random(n) is that output × 2⁻³² × n.

Summary

Functions

One of values (choose): one output modulo how many there are picks it.

A whole number from 0 to n inclusive, or from n to 0 when n is negative (irandom(n)): two outputs make a 63-bit number, the second's low 31 bits above the first's 32, taken modulo |n| + 1 and given n's sign.

A whole number from low to high inclusive (irandom_range).

A generator seeded with seed (random_set_seed).

The next 32-bit output, and the generator after it.

A real from 0 up to n (random(n)).

A real from low up to high (random_range).

Types

t()

@type t() :: %Cauldron2D.GameMaker.Random{
  index: 0..15,
  seed: integer(),
  state: tuple()
}

Functions

choose(random, values)

@spec choose(t(), [term(), ...]) :: {term(), t()}

One of values (choose): one output modulo how many there are picks it.

irandom(random, n)

@spec irandom(t(), number()) :: {integer(), t()}

A whole number from 0 to n inclusive, or from n to 0 when n is negative (irandom(n)): two outputs make a 63-bit number, the second's low 31 bits above the first's 32, taken modulo |n| + 1 and given n's sign.

irandom_range(random, low, high)

@spec irandom_range(t(), number(), number()) :: {integer(), t()}

A whole number from low to high inclusive (irandom_range).

new(seed)

@spec new(integer()) :: t()

A generator seeded with seed (random_set_seed).

next(random)

@spec next(t()) :: {non_neg_integer(), t()}

The next 32-bit output, and the generator after it.

random(random, n)

@spec random(t(), number()) :: {float(), t()}

A real from 0 up to n (random(n)).

random_range(random, low, high)

@spec random_range(t(), number(), number()) :: {float(), t()}

A real from low up to high (random_range).