Rand#
- class Rand(**kwargs)#
The GRand struct is an opaque data structure. It should only be accessed through the ``g_rand_``* functions.
Constructors#
- class Rand
- classmethod new() 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) Rand #
Creates a new random number generator initialized with
seed
.- Parameters:
seed – a value to initialize the random number generator
- classmethod new_with_seed_array(seed: int, seed_length: int) Rand #
Creates a new random number generator initialized with
seed
.Added in version 2.4.
- Parameters:
seed – an array of seeds to initialize the random number generator
seed_length – an array of seeds to initialize the random number generator
Methods#
- class Rand
- double() float #
Returns the next random
float
from @``rand_`` equally distributed over the range [0..1).
- double_range(begin: float, end: float) float #
Returns the next random
float
from @``rand_`` equally distributed over the range [begin
..``end``).- Parameters:
begin – lower closed bound of the interval
end – upper open bound of the interval
- int() int #
Returns the next random
guint32
from @``rand_`` equally distributed over the range [0..2^32-1].
- int_range(begin: int, end: int) int #
Returns the next random
int
from @``rand_`` equally distributed over the range [begin
..``end``-1].- Parameters:
begin – lower closed bound of the interval
end – upper open bound of the interval
- set_seed(seed: int) None #
Sets the seed for the random number generator
Rand
toseed
.- Parameters:
seed – a value to reinitialize the random number generator
- 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.
Added in version 2.4.
- Parameters:
seed – array to initialize with
seed_length – length of array