Class RandomArray

java.lang.Object
org.flag4j.rng.RandomArray

public final class RandomArray extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a RandomArray object to generate arrays filled with random values using a default random number generator.
    Creates a RandomArray object to generate arrays filled with random values using the specified complex random number generator.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    randomFill(double[] arr, Distribution<Double,Random> distribution)
    Fills an array with pseudorandom values sampled from the specified distribution.
    static void
    randomFill(int[] arr, Distribution<Integer,Random> distribution)
    Fills an array with pseudorandom values sampled from the specified distribution.
    static void
    Fills an array with pseudorandom values sampled from the specified distribution.
    static void
    Fills an array with pseudorandom values sampled from the specified distribution.
    int[][]
    randomUniqueIndices2D(int numIndices, int rowStart, int rowEnd, int colStart, int colEnd)
    Creates a list of unique two-dimensional indices.
    int[]
    randomUniqueIntegers(int numIntegers, int start, int end)
    Generates an array of unique integers in range [start, end).
    void
    shuffle(double[] arr)
    Randomly shuffles array using the Fisher–Yates algorithm.
    void
    shuffle(int[] arr)
    Randomly shuffles array using the Fisher–Yates algorithm.
    void
    shuffle(Object[] arr)
    Randomly shuffles array using the Fisher–Yates algorithm.

    Methods inherited from class java.lang.Object

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

    • RandomArray

      public RandomArray()
      Creates a RandomArray object to generate arrays filled with random values using a default random number generator. The seed of the random number generator will be set to RandomState.getGlobalSeed()
    • RandomArray

      public RandomArray(RandomComplex rng)
      Creates a RandomArray object to generate arrays filled with random values using the specified complex random number generator.
      Parameters:
      rng - The complex random number generator to use when creating random arrays.
  • Method Details

    • randomFill

      public static void randomFill(int[] arr, Distribution<Integer,Random> distribution)
      Fills an array with pseudorandom values sampled from the specified distribution.
      Parameters:
      arr - The array to fill.
      distribution - The distribution to sample from.
    • randomFill

      public static void randomFill(double[] arr, Distribution<Double,Random> distribution)
      Fills an array with pseudorandom values sampled from the specified distribution.
      Parameters:
      arr - The array to fill.
      distribution - The distribution to sample from.
    • randomFill

      public static void randomFill(Complex128[] arr, Distribution<Complex128,RandomComplex> distribution)
      Fills an array with pseudorandom values sampled from the specified distribution.
      Parameters:
      arr - The array to fill.
      distribution - The distribution to sample from.
    • randomFill

      public static void randomFill(Complex64[] arr, Distribution<Complex64,RandomComplex> distribution)
      Fills an array with pseudorandom values sampled from the specified distribution.
      Parameters:
      arr - The array to fill.
      distribution - The distribution to sample from.
    • randomUniqueIntegers

      public int[] randomUniqueIntegers(int numIntegers, int start, int end)
      Generates an array of unique integers in range [start, end).
      Parameters:
      numIntegers - Number of random unique integers to get.
      start - Staring index (inclusive).
      end - Ending index (exclusive).
      Returns:
      An array of length numIntegers containing random unique integers in [start, end). The array will be sorted.
      Throws:
      IllegalArgumentException - If start is not in [0, end)
      See Also:
    • randomUniqueIndices2D

      public int[][] randomUniqueIndices2D(int numIndices, int rowStart, int rowEnd, int colStart, int colEnd)
      Creates a list of unique two-dimensional indices.
      Parameters:
      numIndices - Total number of indices to generate.
      rowStart - Starting row index (inclusive).
      rowEnd - Ending row index (exclusive).
      colStart - Starting column index (inclusive).
      colEnd - Ending column index (exclusive).
      Returns:
      A two-dimensional array of shape 2&times;numIndices containing unique two-dimensional indices. The first row contains row indices, the second, column indices. The indices will be sorted by rows then columns.
      See Also:
    • shuffle

      public void shuffle(int[] arr)
      Randomly shuffles array using the Fisher–Yates algorithm. This is done in place.
      Parameters:
      arr - Array to shuffle.
    • shuffle

      public void shuffle(double[] arr)
      Randomly shuffles array using the Fisher–Yates algorithm. This is done in place.
      Parameters:
      arr - Array to shuffle.
    • shuffle

      public void shuffle(Object[] arr)
      Randomly shuffles array using the Fisher–Yates algorithm. This is done in place.
      Parameters:
      arr - Array to shuffle.