random -- Random numbers. ========================= .. This document was autogenerated by Sphinx-autoapi from a .pyi stub or a source code file. .. Do not edit this file, instead edit the source file and run Sphinx to update. .. Source: docs/stubs/random/__init__.pyi .. py:module:: random .. autoapi-nested-parse:: Random numbers. This module implements a pseudo-random number generator (PRNG). |see_cpython_module| :mod:`python:random` . .. note:: The following notation is used for intervals: - () are open interval brackets and do not include their endpoints. For example, (0, 1) means greater than 0 and less than 1. In set notation: (0, 1) = {x | 0 < x < 1}. - [] are closed interval brackets which include all their limit points. For example, [0, 1] means greater than or equal to 0 and less than or equal to 1. In set notation: [0, 1] = {x | 0 <= x <= 1}. .. note:: The :func:`randrange`, :func:`randint` and :func:`choice` functions are only available if the ``MICROPY_PY_RANDOM_EXTRA_FUNCS`` configuration option is enabled. Functions --------- .. autoapisummary:: random.choice random.getrandbits random.randint random.random random.randrange random.seed random.uniform Module Contents --------------- .. py:function:: choice(sequence) -> _typeshed.Incomplete Chooses and returns one item at random from *sequence* (tuple, list or any object that supports the subscript operation). .. py:function:: getrandbits(n) -> int Return an integer with *n* random bits (0 <= n <= 32). .. py:function:: randint(a, b) -> int Return a random integer in the range [*a*, *b*]. .. py:function:: random() -> int Return a random floating point number in the range [0.0, 1.0). .. py:function:: randrange(start, stop, step: Optional[Any] = None) -> int The first form returns a random integer from the range [0, *stop*). The second form returns a random integer from the range [*start*, *stop*). The third form returns a random integer from the range [*start*, *stop*) in steps of *step*. For instance, calling ``randrange(1, 10, 2)`` will return odd numbers between 1 and 9 inclusive. .. py:function:: seed(n=None) -> None Initialise the random number generator module with the seed *n* which should be an integer. When no argument (or ``None``) is passed in it will (if supported by the port) initialise the PRNG with a true random number (usually a hardware generated random number). The ``None`` case only works if ``MICROPY_PY_RANDOM_SEED_INIT_FUNC`` is enabled by the port, otherwise it raises ``ValueError``. .. py:function:: uniform(a, b) -> int Return a random floating point number N such that *a* <= N <= *b* for *a* <= *b*, and *b* <= N <= *a* for *b* < *a*.