GLib.Rand

Fields

None

Methods

class

new ()

class

new_with_seed (seed)

class

new_with_seed_array (seed, seed_length)

copy ()

double ()

double_range (begin, end)

free ()

int ()

int_range (begin, end)

set_seed (seed)

set_seed_array (seed, seed_length)

Details

class GLib.Rand

The GLib.Rand struct is an opaque data structure. It should only be accessed through the g_rand_* functions.

classmethod new()[source]
Returns:

the new GLib.Rand

Return type:

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)[source]
Parameters:

seed (int) – a value to initialize the random number generator

Returns:

the new GLib.Rand

Return type:

GLib.Rand

Creates a new random number generator initialized with seed.

classmethod new_with_seed_array(seed, seed_length)[source]
Parameters:
  • seed (int) – an array of seeds to initialize the random number generator

  • seed_length (int) – an array of seeds to initialize the random number generator

Returns:

the new GLib.Rand

Return type:

GLib.Rand

Creates a new random number generator initialized with seed.

New in version 2.4.

copy()[source]
Returns:

the new GLib.Rand

Return type:

GLib.Rand

Copies a GLib.Rand into a new one with the same exact state as before. This way you can take a snapshot of the random number generator for replaying later.

New in version 2.4.

double()[source]
Returns:

a random number

Return type:

float

Returns the next random float from self equally distributed over the range [0..1).

double_range(begin, end)[source]
Parameters:
  • begin (float) – lower closed bound of the interval

  • end (float) – upper open bound of the interval

Returns:

a random number

Return type:

float

Returns the next random float from self equally distributed over the range [begin..`end`).

free()[source]

Frees the memory allocated for the GLib.Rand.

int()[source]
Returns:

a random number

Return type:

int

Returns the next random #guint32 from self equally distributed over the range [0..2^32-1].

int_range(begin, end)[source]
Parameters:
  • begin (int) – lower closed bound of the interval

  • end (int) – upper open bound of the interval

Returns:

a random number

Return type:

int

Returns the next random #gint32 from self equally distributed over the range [begin..`end`-1].

set_seed(seed)[source]
Parameters:

seed (int) – a value to reinitialize the random number generator

Sets the seed for the random number generator GLib.Rand to seed.

set_seed_array(seed, seed_length)[source]
Parameters:
  • seed (int) – array to initialize with

  • seed_length (int) – length of array

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.

New in version 2.4.