Package org.gnome.glib
Class Rand
java.lang.Object
org.javagi.base.ProxyInstance
org.gnome.glib.Rand
- All Implemented Interfaces:
Proxy
The GRand struct is an opaque data structure. It should only be
accessed through the g_rand_* functions.
-
Constructor Summary
ConstructorsConstructorDescriptionRand()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).Rand(MemorySegment address) Create a Rand proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Copies aGRandinto a new one with the same exact state as before.doubledouble_()Returns the next randomgdoublefrom this Rand equally distributed over the range [0..1).doubledoubleRange(double begin, double end) Returns the next randomgdoublefrom this Rand equally distributed over the range [end).voidfree()Frees the memory allocated for theGRand.static @Nullable TypegetType()Get the GType of the Rand classintint_()Returns the next randomguint32from this Rand equally distributed over the range [0..2^32-1].intintRange(int begin, int end) Returns the next randomgint32from this Rand equally distributed over the rangeend-1.voidsetSeed(int seed) Sets the seed for the random number generatorGRandtoseed.voidsetSeedArray(MemorySegment seed, int seedLength) Initializes the random number generator by an array of longs.static RandwithSeed(int seed) Creates a new random number generator initialized withseed.static RandwithSeedArray(MemorySegment seed, int seedLength) Creates a new random number generator initialized withseed.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Rand
Create a Rand proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Rand
public 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().
-
-
Method Details
-
getType
-
withSeed
Creates a new random number generator initialized withseed.- Parameters:
seed- a value to initialize the random number generator- Returns:
- the new
GRand
-
withSeedArray
Creates a new random number generator initialized withseed.- Parameters:
seed- an array of seeds to initialize the random number generatorseedLength- an array of seeds to initialize the random number generator- Returns:
- the new
GRand - Since:
- 2.4
-
copy
Copies aGRandinto 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.- Returns:
- the new
GRand - Since:
- 2.4
-
double_
public double double_()Returns the next randomgdoublefrom this Rand equally distributed over the range [0..1).- Returns:
- a random number
-
doubleRange
public double doubleRange(double begin, double end) Returns the next randomgdoublefrom this Rand equally distributed over the range [end).- Parameters:
begin- lower closed bound of the intervalend- upper open bound of the interval- Returns:
- a random number
-
free
public void free()Frees the memory allocated for theGRand. -
int_
public int int_()Returns the next randomguint32from this Rand equally distributed over the range [0..2^32-1].- Returns:
- a random number
-
intRange
public int intRange(int begin, int end) Returns the next randomgint32from this Rand equally distributed over the rangeend-1.- Parameters:
begin- lower closed bound of the intervalend- upper open bound of the interval- Returns:
- a random number
-
setSeed
public void setSeed(int seed) Sets the seed for the random number generatorGRandtoseed.- Parameters:
seed- a value to reinitialize the random number generator
-
setSeedArray
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.- Parameters:
seed- array to initialize withseedLength- length of array- Since:
- 2.4
-