Random Number Generators tcod.random
¶
Ports of the libtcod random number generator.
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: Hashable | None = 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
Warning
A non-integer seed is only deterministic if the environment variable
PYTHONHASHSEED
is set. In the future this function will only accept int’s as a seed.Changed in version 9.1: Added tcod.random.MULTIPLY_WITH_CARRY constant. algorithm parameter now defaults to tcod.random.MERSENNE_TWISTER.
- __setstate__(state: dict[str, Any]) None [source]¶
Create a new cdata object with the stored parameters.
- gauss(mu: float, sigma: float) float [source]¶
Return a random number using Gaussian distribution.
- Parameters:
- Returns:
A random float.
- Return type:
Changed in version 16.2: Renamed from guass to gauss.
- inverse_gauss(mu: float, sigma: float) float [source]¶
Return a random Gaussian number using the Box-Muller transform.
- Parameters:
- Returns:
A random float.
- Return type:
Changed in version 16.2: Renamed from inverse_guass to inverse_gauss.