:github_url: hide .. Generated automatically by doc/tools/makerst.py in Godot's source tree. .. DO NOT EDIT THIS FILE, but the RandomNumberGenerator.xml source instead. .. The source is found in doc/classes or modules//doc_classes. .. _class_RandomNumberGenerator: RandomNumberGenerator ===================== **Inherits:** :ref:`Reference` **<** :ref:`Object` A class for generating pseudo-random numbers. Description ----------- RandomNumberGenerator is a class for generating pseudo-random numbers. It currently uses `PCG32 `_. **Note:** The underlying algorithm is an implementation detail. As a result, it should not be depended upon for reproducible random streams across Godot versions. To generate a random float number (within a given range) based on a time-dependant seed: :: var rng = RandomNumberGenerator.new() func _ready(): rng.randomize() var my_random_number = rng.randf_range(-10.0, 10.0) Properties ---------- +-----------------------+--------------------------------------------------------+--------------------------+ | :ref:`int` | :ref:`seed` | ``-6398989897141750821`` | +-----------------------+--------------------------------------------------------+--------------------------+ Methods ------- +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`randf` **(** **)** | +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`randf_range` **(** :ref:`float` from, :ref:`float` to **)** | +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`randfn` **(** :ref:`float` mean=0.0, :ref:`float` deviation=1.0 **)** | +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`randi` **(** **)** | +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`randi_range` **(** :ref:`int` from, :ref:`int` to **)** | +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`randomize` **(** **)** | +---------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+ Property Descriptions --------------------- .. _class_RandomNumberGenerator_property_seed: - :ref:`int` **seed** +-----------+--------------------------+ | *Default* | ``-6398989897141750821`` | +-----------+--------------------------+ | *Setter* | set_seed(value) | +-----------+--------------------------+ | *Getter* | get_seed() | +-----------+--------------------------+ The seed used by the random number generator. A given seed will give a reproducible sequence of pseudo-random numbers. **Note:** The RNG does not have an avalanche effect, and can output similar random streams given similar seeds. Consider using a hash function to improve your seed quality if they're sourced externally. Method Descriptions ------------------- .. _class_RandomNumberGenerator_method_randf: - :ref:`float` **randf** **(** **)** Generates a pseudo-random float between ``0.0`` and ``1.0`` (inclusive). ---- .. _class_RandomNumberGenerator_method_randf_range: - :ref:`float` **randf_range** **(** :ref:`float` from, :ref:`float` to **)** Generates a pseudo-random float between ``from`` and ``to`` (inclusive). ---- .. _class_RandomNumberGenerator_method_randfn: - :ref:`float` **randfn** **(** :ref:`float` mean=0.0, :ref:`float` deviation=1.0 **)** Generates a `normally-distributed `_ pseudo-random number, using Box-Muller transform with the specified ``mean`` and a standard ``deviation``. This is also called Gaussian distribution. ---- .. _class_RandomNumberGenerator_method_randi: - :ref:`int` **randi** **(** **)** Generates a pseudo-random 32-bit unsigned integer between ``0`` and ``4294967295`` (inclusive). ---- .. _class_RandomNumberGenerator_method_randi_range: - :ref:`int` **randi_range** **(** :ref:`int` from, :ref:`int` to **)** Generates a pseudo-random 32-bit signed integer between ``from`` and ``to`` (inclusive). ---- .. _class_RandomNumberGenerator_method_randomize: - void **randomize** **(** **)** Setups a time-based seed to generator. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`