Class Rand

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Rand extends ProxyInstance
The GRand struct is an opaque data structure. It should only be accessed through the g_rand_* functions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    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).
    Create a Rand proxy instance for the provided memory address.
  • Method Summary

    Modifier and Type
    Method
    Description
    Copies a GRand into a new one with the same exact state as before.
    double
    Returns the next random gdouble from this Rand equally distributed over the range [0..1).
    double
    doubleRange(double begin, double end)
    Returns the next random gdouble from this Rand equally distributed over the range [end).
    void
    Frees the memory allocated for the GRand.
    The memory layout of the native struct.
    static @Nullable Type
    Get the GType of the Rand class.
    int
    Returns the next random guint32 from this Rand equally distributed over the range [0..2^32-1].
    int
    intRange(int begin, int end)
    Returns the next random gint32 from this Rand equally distributed over the range end-1.
    void
    setSeed(int seed)
    Sets the seed for the random number generator GRand to seed.
    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 with seed.
    static Rand
    withSeedArray(MemorySegment seed, int seedLength)
    Creates a new random number generator initialized with seed.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Rand

      public Rand(MemorySegment address)
      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

      public static @Nullable Type getType()
      Get the GType of the Rand class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • withSeed

      public static Rand withSeed(int seed)
      Creates a new random number generator initialized with seed.
      Parameters:
      seed - a value to initialize the random number generator
      Returns:
      the new GRand
    • withSeedArray

      public static Rand withSeedArray(MemorySegment seed, int seedLength)
      Creates a new random number generator initialized with seed.
      Parameters:
      seed - an array of seeds to initialize the random number generator
      seedLength - an array of seeds to initialize the random number generator
      Returns:
      the new GRand
      Since:
      2.4
    • copy

      public Rand copy()
      Copies a GRand 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
      Since:
      2.4
    • double_

      public double double_()
      Returns the next random gdouble 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 random gdouble from this Rand equally distributed over the range [end).
      Parameters:
      begin - lower closed bound of the interval
      end - upper open bound of the interval
      Returns:
      a random number
    • free

      public void free()
      Frees the memory allocated for the GRand.
    • int_

      public int int_()
      Returns the next random guint32 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 random gint32 from this Rand equally distributed over the range end-1.
      Parameters:
      begin - lower closed bound of the interval
      end - upper open bound of the interval
      Returns:
      a random number
    • setSeed

      public void setSeed(int seed)
      Sets the seed for the random number generator GRand to seed.
      Parameters:
      seed - a value to reinitialize the random number generator
    • setSeedArray

      public void setSeedArray(MemorySegment seed, int seedLength)
      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 with
      seedLength - length of array
      Since:
      2.4