:right-sidebar: True Rand =================================================================== .. currentmodule:: gi.repository.GLib .. class:: Rand(**kwargs) :no-contents-entry: The GRand struct is an opaque data structure. It should only be accessed through the ``g_rand_``\* functions. Constructors ------------ .. rst-class:: interim-class .. class:: Rand :no-index: .. classmethod:: new() -> ~gi.repository.GLib.Rand Creates a new random number generator initialized with a seed taken either from ``/dev/urandom`` (if existing) or from the current time (as a fallback). On Windows, the seed is taken from rand_s(). .. classmethod:: new_with_seed(seed: int) -> ~gi.repository.GLib.Rand Creates a new random number generator initialized with ``seed``\. :param seed: a value to initialize the random number generator .. classmethod:: new_with_seed_array(seed: int, seed_length: int) -> ~gi.repository.GLib.Rand Creates a new random number generator initialized with ``seed``\. .. versionadded:: 2.4 :param seed: an array of seeds to initialize the random number generator :param seed_length: an array of seeds to initialize the random number generator Methods ------- .. rst-class:: interim-class .. class:: Rand :no-index: .. method:: double() -> float Returns the next random :obj:`float` from ``rand_`` equally distributed over the range [0..1). .. method:: double_range(begin: float, end: float) -> float Returns the next random :obj:`float` from ``rand_`` equally distributed over the range [``begin``\..``end``\). :param begin: lower closed bound of the interval :param end: upper open bound of the interval .. method:: free() -> None Frees the memory allocated for the :obj:`~gi.repository.GLib.Rand`\. .. method:: int() -> int Returns the next random :obj:`int` from ``rand_`` equally distributed over the range [0..2^32-1]. .. method:: int_range(begin: int, end: int) -> int Returns the next random :obj:`int` from ``rand_`` equally distributed over the range [``begin``\..``end``\-1]. :param begin: lower closed bound of the interval :param end: upper open bound of the interval .. method:: set_seed(seed: int) -> None Sets the seed for the random number generator :obj:`~gi.repository.GLib.Rand` to ``seed``\. :param seed: a value to reinitialize the random number generator .. method:: set_seed_array(seed: int, seed_length: int) -> None Initializes the random number generator by an array of longs. Array can be of arbitrary size, though only the first 624 values are taken. This function is useful if you have many low entropy seeds, or if you require more then 32 bits of actual entropy for your application. .. versionadded:: 2.4 :param seed: array to initialize with :param seed_length: length of array