Package org.gnome.glib
Class Rand
java.lang.Object
io.github.jwharm.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
ConstructorDescriptionRand()
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 aGRand
into a new one with the same exact state as before.double
double_()
Returns the next randomgdouble
from this Rand equally distributed over the range [0..1).double
doubleRange
(double begin, double end) Returns the next randomgdouble
from this Rand equally distributed over the range [begin
..end
).void
free()
Frees the memory allocated for theGRand
.static Type
getType()
Get the GType of the Rand classint
int_()
Returns the next randomguint32
from this Rand equally distributed over the range [0..2^32-1].int
intRange
(int begin, int end) Returns the next randomgint32
from this Rand equally distributed over the rangeend-1
.void
setSeed
(int seed) Sets the seed for the random number generatorGRand
toseed
.void
setSeedArray
(MemorySegment seed, int seedLength) Initializes the random number generator by an array of longs.static Rand
withSeed
(int seed) Creates a new random number generator initialized withseed
.static Rand
withSeedArray
(MemorySegment seed, int seedLength) Creates a new random number generator initialized withseed
.Methods inherited from class io.github.jwharm.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
-
copy
Copies aGRand
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.- Returns:
- the new
GRand
-
double_
public double double_()Returns the next randomgdouble
from this Rand equally distributed over the range [0..1).- Returns:
- a random number
-
doubleRange
public double doubleRange(double begin, double end) Returns the next randomgdouble
from this Rand equally distributed over the range [begin
..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 randomguint32
from 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 randomgint32
from 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 generatorGRand
toseed
.- 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
-