Class RandomArray

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

public final class RandomArray extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a RandomArrayOld object to generate arrays filled with random values using a default random number generator.
    Creates a RandomArrayOld 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[]
    randomUniqueIndices(int numIndices, int start, int end)
    Creates unique indices in [start, end).
    int[][]
    randomUniqueIndices2D(int numIndices, int rowStart, int rowEnd, int colStart, int colEnd)
    Creates a list of unique two-dimensional indices.
    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 RandomArrayOld object to generate arrays filled with random values using a default random number generator.
    • RandomArray

      public RandomArray(RandomComplex rng)
      Creates a RandomArrayOld 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.
    • randomUniqueIndices

      public int[] randomUniqueIndices(int numIndices, int start, int end)
      Creates unique indices in [start, end).
      Parameters:
      numIndices - Number of random unique indices to get.
      start - Staring index (inclusive).
      end - Ending index (exclusive).
      Returns:
      An array of length numIndices containing random unique indices 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-by-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.