tcod.random

Usually it’s recommend to the Python’s standard library random module instead of this one.

However, you will need to use these generators to get deterministic results from the Noise and BSP classes.

class tcod.random.Random(algorithm: int = 0, seed: Optional[Hashable] = None)[source]

The libtcod random number generator.

algorithm defaults to Mersenne Twister, it can be one of:

  • tcod.random.MERSENNE_TWISTER
  • tcod.random.MULTIPLY_WITH_CARRY

seed is a 32-bit number or any Python hashable object like a string. Using the same seed will cause the generator to return deterministic values. The default seed of None will generate a random seed instead.

random_c

A cffi pointer to a TCOD_random_t object.

Type:CData

Changed in version 9.1: Added tcod.random.MULTIPLY_WITH_CARRY constant. algorithm parameter now defaults to tcod.random.MERSENNE_TWISTER.

__getstate__() → Any[source]

Pack the self.random_c attribute into a portable state.

__setstate__(state: Any) → None[source]

Create a new cdata object with the stored paramaters.

guass(mu: float, sigma: float) → float[source]

Return a random number using Gaussian distribution.

Parameters:
  • mu (float) – The median returned value.
  • sigma (float) – The standard deviation.
Returns:

A random float.

Return type:

float

inverse_guass(mu: float, sigma: float) → float[source]

Return a random Gaussian number using the Box-Muller transform.

Parameters:
  • mu (float) – The median returned value.
  • sigma (float) – The standard deviation.
Returns:

A random float.

Return type:

float

randint(low: int, high: int) → int[source]

Return a random integer within the linear range: low <= n <= high.

Parameters:
  • low (int) – The lower bound of the random range.
  • high (int) – The upper bound of the random range.
Returns:

A random integer.

Return type:

int

uniform(low: float, high: float) → float[source]

Return a random floating number in the range: low <= n <= high.

Parameters:
  • low (float) – The lower bound of the random range.
  • high (float) – The upper bound of the random range.
Returns:

A random float.

Return type:

float