Class RandomArray
java.lang.Object
org.flag4j.rng.RandomArray
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a RandomArrayOld object to generate arrays filled with random values using a default random number generator.RandomArray
(RandomComplex rng) Creates a RandomArrayOld object to generate arrays filled with random values using the specified complex random number generator. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
randomFill
(double[] arr, Distribution<Double, Random> distribution) Fills an array with pseudorandom values sampled from the specifieddistribution
.static void
randomFill
(int[] arr, Distribution<Integer, Random> distribution) Fills an array with pseudorandom values sampled from the specifieddistribution
.static void
randomFill
(Complex128[] arr, Distribution<Complex128, RandomComplex> distribution) Fills an array with pseudorandom values sampled from the specifieddistribution
.static void
randomFill
(Complex64[] arr, Distribution<Complex64, RandomComplex> distribution) Fills an array with pseudorandom values sampled from the specifieddistribution
.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
Randomly shuffles array using the Fisher–Yates algorithm.
-
Constructor Details
-
RandomArray
public RandomArray()Creates a RandomArrayOld object to generate arrays filled with random values using a default random number generator. -
RandomArray
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
Fills an array with pseudorandom values sampled from the specifieddistribution
.- Parameters:
arr
- The array to fill.distribution
- The distribution to sample from.
-
randomFill
Fills an array with pseudorandom values sampled from the specifieddistribution
.- 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 specifieddistribution
.- Parameters:
arr
- The array to fill.distribution
- The distribution to sample from.
-
randomFill
Fills an array with pseudorandom values sampled from the specifieddistribution
.- 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
- Ifstart
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
Randomly shuffles array using the Fisher–Yates algorithm. This is done in place.- Parameters:
arr
- Array to shuffle.
-