Package squidpony

Class ArrayTools

java.lang.Object
squidpony.ArrayTools

public class ArrayTools
extends Object
Static methods for various frequently-used operations on 1D and 2D arrays. Has methods for copying, inserting, and filling 2D arrays of primitive types (char, int, double, and boolean). Has a few mehods for creating ranges of ints or chars easily as 1D arrays. Also contains certain methods for working with orderings, which can be naturally used with OrderedMap, OrderedSet, K2, and similar ordered collections plus ArrayList using reorder(ArrayList, int...) in this class. Created by Tommy Ettinger on 11/17/2016.
  • Constructor Summary

    Constructors 
    Constructor Description
    ArrayTools()  
  • Method Summary

    Modifier and Type Method Description
    static char[] charSpan​(char start, char end)
    Stupidly simple convenience method that produces a char range from start to end, including end, as a char array.
    static boolean[][] copy​(boolean[][] source)
    Gets a copy of the 2D boolean array, source, that has the same data but shares no references with source.
    static char[][] copy​(char[][] source)
    Gets a copy of the 2D char array, source, that has the same data but shares no references with source.
    static double[][] copy​(double[][] source)
    Gets a copy of the 2D double array, source, that has the same data but shares no references with source.
    static float[][] copy​(float[][] source)
    Gets a copy of the 2D float array, source, that has the same data but shares no references with source.
    static int[][] copy​(int[][] source)
    Gets a copy of the 2D int array, source, that has the same data but shares no references with source.
    static void fill​(boolean[][] array2d, boolean value)
    Fills array2d with value.
    static void fill​(boolean[][] array2d, boolean value, int startX, int startY, int endX, int endY)
    Fills a sub-section of array2d with value, with the section defined by start/end x/y.
    static boolean[][] fill​(boolean contents, int width, int height)
    Creates a 2D array of the given width and height, filled with entirely with the value contents.
    static void fill​(byte[][] array2d, byte value)
    Fills array2d with value.
    static byte[][] fill​(byte contents, int width, int height)
    Creates a 2D array of the given width and height, filled with entirely with the value contents.
    static void fill​(char[][] array2d, char value)
    Fills array2d with value.
    static void fill​(char[][] array2d, char value, int startX, int startY, int endX, int endY)
    Fills a sub-section of array2d with value, with the section defined by start/end x/y.
    static char[][] fill​(char contents, int width, int height)
    Creates a 2D array of the given width and height, filled with entirely with the value contents.
    static void fill​(double[][][] array3d, double value)
    Fills array3d with value.
    static void fill​(double[][] array2d, double value)
    Fills array2d with value.
    static void fill​(double[][] array2d, double value, int startX, int startY, int endX, int endY)
    Fills a sub-section of array2d with value, with the section defined by start/end x/y.
    static double[][] fill​(double contents, int width, int height)
    Creates a 2D array of the given width and height, filled with entirely with the value contents.
    static void fill​(float[][] array2d, float value)
    Fills array2d with value.
    static void fill​(float[][] array2d, float value, int startX, int startY, int endX, int endY)
    Fills a sub-section of array2d with value, with the section defined by start/end x/y.
    static float[][] fill​(float contents, int width, int height)
    Creates a 2D array of the given width and height, filled with entirely with the value contents.
    static void fill​(int[][] array2d, int value)
    Fills array2d with value.
    static void fill​(int[][] array2d, int value, int startX, int startY, int endX, int endY)
    Fills a sub-section of array2d with value, with the section defined by start/end x/y.
    static int[][] fill​(int contents, int width, int height)
    Creates a 2D array of the given width and height, filled with entirely with the value contents.
    static boolean[][] insert​(boolean[][] source, boolean[][] target, int x, int y)
    Inserts as much of source into target at the given x,y position as target can hold or source can supply.
    static char[][] insert​(char[][] source, char[][] target, int x, int y)
    Inserts as much of source into target at the given x,y position as target can hold or source can supply.
    static double[][] insert​(double[][] source, double[][] target, int x, int y)
    Inserts as much of source into target at the given x,y position as target can hold or source can supply.
    static float[][] insert​(float[][] source, float[][] target, int x, int y)
    Inserts as much of source into target at the given x,y position as target can hold or source can supply.
    static int[][] insert​(int[][] source, int[][] target, int x, int y)
    Inserts as much of source into target at the given x,y position as target can hold or source can supply.
    static int[] invertOrdering​(int[] ordering)
    Given an ordering such as one produced by RNG.randomOrdering(int, int[]), this finds its inverse, able to reverse the reordering and vice versa.
    static int[] invertOrdering​(int[] ordering, int[] dest)
    Given an ordering such as one produced by RNG.randomOrdering(int, int[]), this finds its inverse, able to reverse the reordering and vice versa.
    static char letterAt​(int index)
    Gets the nth letter from the set that SquidLib is likely to support; from index 0 (returning 'A') to 255 (returning the Greek lower-case letter gamma, 'γ') and wrapping around if given negative numbers or numbers larger than 255.
    static char[] letterSpan​(int charCount)
    Stupidly simple convenience method that produces a char array containing only letters that can be reasonably displayed (with SquidLib's default text display assets, at least).
    static void randomFill​(char[][] array2d, char[] values, long seed)
    Randomly fills all of array2d with random values generated from seed, choosing chars to place in the given 2D array by selecting them at random from the given 1D char array values.
    static void randomFill​(char[][] array2d, CharSequence values, long seed)
    Randomly fills all of array2d with random values generated from seed, choosing chars to place in the given 2D array by selecting them at random from the given 1D char array values.
    static void randomFill​(double[][] array2d, double bound, long seed)
    Randomly fills all of array2d with random values generated from seed, limiting results to between 0 and bound, exclusive.
    static void randomFill​(double[][] array2d, long seed)
    Randomly fills all of array2d with random values generated from seed; can fill an element with any double between 0.0 inclusive and 1.0 exclusive.
    static void randomFill​(float[][] array2d, float bound, long seed)
    Randomly fills all of array2d with random values generated from seed, limiting results to between 0 and bound, exclusive.
    static void randomFill​(float[][] array2d, long seed)
    Randomly fills all of array2d with random values generated from seed; can fill an element with any float between 0.0 inclusive and 1.0 exclusive.
    static void randomFill​(int[][] array2d, int bound, long seed)
    Randomly fills all of array2d with random values generated from seed, limiting results to between 0 and bound, exclusive.
    static void randomFill​(int[][] array2d, long seed)
    Randomly fills all of array2d with random values generated from seed; can fill an element with any int, positive or negative.
    static void randomFill​(long[][] array2d, long seed)
    Randomly fills all of array2d with random values generated from seed; can fill an element with any long, positive or negative.
    static int[] range​(int end)
    Stupidly simple convenience method that produces a range from 0 to end, not including end, as an int array.
    static int[] range​(int start, int end)
    Stupidly simple convenience method that produces a range from start to end, not including end, as an int array.
    static <T> ArrayList<T> reorder​(ArrayList<T> list, int... ordering)
    Rearranges an ArrayList to use the given ordering, returning a copy; random orderings can be produced with RNG.randomOrdering(int) or RNG.randomOrdering(int, int[]).
    static boolean[] reverse​(boolean[] data)
    Reverses the array given as a parameter, in-place, and returns the modified original.
    static byte[] reverse​(byte[] data)
    Reverses the array given as a parameter, in-place, and returns the modified original.
    static char[] reverse​(char[] data)
    Reverses the array given as a parameter, in-place, and returns the modified original.
    static double[] reverse​(double[] data)
    Reverses the array given as a parameter, in-place, and returns the modified original.
    static float[] reverse​(float[] data)
    Reverses the array given as a parameter, in-place, and returns the modified original.
    static int[] reverse​(int[] data)
    Reverses the array given as a parameter, in-place, and returns the modified original.
    static <T> T[] reverse​(T[] data)
    Reverses the array given as a parameter, in-place, and returns the modified original.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • range

      public static int[] range​(int end)
      Stupidly simple convenience method that produces a range from 0 to end, not including end, as an int array.
      Parameters:
      end - the exclusive upper bound on the range
      Returns:
      the range of ints as an int array
    • range

      public static int[] range​(int start, int end)
      Stupidly simple convenience method that produces a range from start to end, not including end, as an int array.
      Parameters:
      start - the inclusive lower bound on the range
      end - the exclusive upper bound on the range
      Returns:
      the range of ints as an int array
    • charSpan

      public static char[] charSpan​(char start, char end)
      Stupidly simple convenience method that produces a char range from start to end, including end, as a char array.
      Parameters:
      start - the inclusive lower bound on the range, such as 'a'
      end - the inclusive upper bound on the range, such as 'z'
      Returns:
      the range of chars as a char array
    • letterSpan

      public static char[] letterSpan​(int charCount)
      Stupidly simple convenience method that produces a char array containing only letters that can be reasonably displayed (with SquidLib's default text display assets, at least). The letters are copied from a single source of 256 chars; if you need more chars or you don't need pure letters, you can use charSpan(char, char). This set does not contain "visual duplicate" letters, such as Latin alphabet capital letter 'A' and Greek alphabet capital letter alpha, 'Α'; it does contain many accented Latin letters and the visually-distinct Greek letters, up to a point.
      Parameters:
      charCount - the number of letters to return in an array; the maximum this will produce is 256
      Returns:
      the range of letters as a char array
    • letterAt

      public static char letterAt​(int index)
      Gets the nth letter from the set that SquidLib is likely to support; from index 0 (returning 'A') to 255 (returning the Greek lower-case letter gamma, 'γ') and wrapping around if given negative numbers or numbers larger than 255. This set does not contain "visual duplicate" letters, such as Latin alphabet capital letter 'A' and Greek alphabet capital letter alpha, 'Α'; it does contain many accented Latin letters and the visually-distinct Greek letters, up to a point.
      Parameters:
      index - typically from 0 to 255, but all ints are allowed and will produce letters
      Returns:
      the letter at the given index in a 256-element portion of the letters SquidLib usually supports
    • copy

      public static char[][] copy​(char[][] source)
      Gets a copy of the 2D char array, source, that has the same data but shares no references with source.
      Parameters:
      source - a 2D char array
      Returns:
      a copy of source, or null if source is null
    • copy

      public static double[][] copy​(double[][] source)
      Gets a copy of the 2D double array, source, that has the same data but shares no references with source.
      Parameters:
      source - a 2D double array
      Returns:
      a copy of source, or null if source is null
    • copy

      public static float[][] copy​(float[][] source)
      Gets a copy of the 2D float array, source, that has the same data but shares no references with source.
      Parameters:
      source - a 2D float array
      Returns:
      a copy of source, or null if source is null
    • copy

      public static int[][] copy​(int[][] source)
      Gets a copy of the 2D int array, source, that has the same data but shares no references with source.
      Parameters:
      source - a 2D int array
      Returns:
      a copy of source, or null if source is null
    • copy

      public static boolean[][] copy​(boolean[][] source)
      Gets a copy of the 2D boolean array, source, that has the same data but shares no references with source.
      Parameters:
      source - a 2D boolean array
      Returns:
      a copy of source, or null if source is null
    • insert

      public static char[][] insert​(char[][] source, char[][] target, int x, int y)
      Inserts as much of source into target at the given x,y position as target can hold or source can supply. Modifies target in-place and also returns target for chaining. Used primarily to place a smaller array into a different position in a larger array, often freshly allocated.
      Parameters:
      source - a 2D char array that will be copied and inserted into target
      target - a 2D char array that will be modified by receiving as much of source as it can hold
      x - the x position in target to receive the items from the first cell in source
      y - the y position in target to receive the items from the first cell in source
      Returns:
      target, modified, with source inserted into it at the given position
    • insert

      public static double[][] insert​(double[][] source, double[][] target, int x, int y)
      Inserts as much of source into target at the given x,y position as target can hold or source can supply. Modifies target in-place and also returns target for chaining. Used primarily to place a smaller array into a different position in a larger array, often freshly allocated.
      Parameters:
      source - a 2D double array that will be copied and inserted into target
      target - a 2D double array that will be modified by receiving as much of source as it can hold
      x - the x position in target to receive the items from the first cell in source
      y - the y position in target to receive the items from the first cell in source
      Returns:
      target, modified, with source inserted into it at the given position
    • insert

      public static float[][] insert​(float[][] source, float[][] target, int x, int y)
      Inserts as much of source into target at the given x,y position as target can hold or source can supply. Modifies target in-place and also returns target for chaining. Used primarily to place a smaller array into a different position in a larger array, often freshly allocated.
      Parameters:
      source - a 2D float array that will be copied and inserted into target
      target - a 2D float array that will be modified by receiving as much of source as it can hold
      x - the x position in target to receive the items from the first cell in source
      y - the y position in target to receive the items from the first cell in source
      Returns:
      target, modified, with source inserted into it at the given position
    • insert

      public static int[][] insert​(int[][] source, int[][] target, int x, int y)
      Inserts as much of source into target at the given x,y position as target can hold or source can supply. Modifies target in-place and also returns target for chaining. Used primarily to place a smaller array into a different position in a larger array, often freshly allocated.
      Parameters:
      source - a 2D int array that will be copied and inserted into target
      target - a 2D int array that will be modified by receiving as much of source as it can hold
      x - the x position in target to receive the items from the first cell in source
      y - the y position in target to receive the items from the first cell in source
      Returns:
      target, modified, with source inserted into it at the given position
    • insert

      public static boolean[][] insert​(boolean[][] source, boolean[][] target, int x, int y)
      Inserts as much of source into target at the given x,y position as target can hold or source can supply. Modifies target in-place and also returns target for chaining. Used primarily to place a smaller array into a different position in a larger array, often freshly allocated.
      Parameters:
      source - a 2D boolean array that will be copied and inserted into target
      target - a 2D boolean array that will be modified by receiving as much of source as it can hold
      x - the x position in target to receive the items from the first cell in source
      y - the y position in target to receive the items from the first cell in source
      Returns:
      target, modified, with source inserted into it at the given position
    • fill

      public static char[][] fill​(char contents, int width, int height)
      Creates a 2D array of the given width and height, filled with entirely with the value contents. You may want to use fill(char[][], char) to modify an existing 2D array instead.
      Parameters:
      contents - the value to fill the array with
      width - the desired width
      height - the desired height
      Returns:
      a freshly allocated 2D array of the requested dimensions, filled entirely with contents
    • fill

      public static float[][] fill​(float contents, int width, int height)
      Creates a 2D array of the given width and height, filled with entirely with the value contents. You may want to use fill(float[][], float) to modify an existing 2D array instead.
      Parameters:
      contents - the value to fill the array with
      width - the desired width
      height - the desired height
      Returns:
      a freshly allocated 2D array of the requested dimensions, filled entirely with contents
    • fill

      public static double[][] fill​(double contents, int width, int height)
      Creates a 2D array of the given width and height, filled with entirely with the value contents. You may want to use fill(double[][], double) to modify an existing 2D array instead.
      Parameters:
      contents - the value to fill the array with
      width - the desired width
      height - the desired height
      Returns:
      a freshly allocated 2D array of the requested dimensions, filled entirely with contents
    • fill

      public static int[][] fill​(int contents, int width, int height)
      Creates a 2D array of the given width and height, filled with entirely with the value contents. You may want to use fill(int[][], int) to modify an existing 2D array instead.
      Parameters:
      contents - the value to fill the array with
      width - the desired width
      height - the desired height
      Returns:
      a freshly allocated 2D array of the requested dimensions, filled entirely with contents
    • fill

      public static byte[][] fill​(byte contents, int width, int height)
      Creates a 2D array of the given width and height, filled with entirely with the value contents. You may want to use fill(byte[][], byte) to modify an existing 2D array instead.
      Parameters:
      contents - the value to fill the array with
      width - the desired width
      height - the desired height
      Returns:
      a freshly allocated 2D array of the requested dimensions, filled entirely with contents
    • fill

      public static boolean[][] fill​(boolean contents, int width, int height)
      Creates a 2D array of the given width and height, filled with entirely with the value contents. You may want to use fill(boolean[][], boolean) to modify an existing 2D array instead.
      Parameters:
      contents - the value to fill the array with
      width - the desired width
      height - the desired height
      Returns:
      a freshly allocated 2D array of the requested dimensions, filled entirely with contents
    • fill

      public static void fill​(boolean[][] array2d, boolean value)
      Fills array2d with value. Not to be confused with fill(boolean, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
    • fill

      public static void fill​(char[][] array2d, char value)
      Fills array2d with value. Not to be confused with fill(char, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
    • fill

      public static void fill​(float[][] array2d, float value)
      Fills array2d with value. Not to be confused with fill(float, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
    • fill

      public static void fill​(double[][] array2d, double value)
      Fills array2d with value. Not to be confused with fill(double, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
    • fill

      public static void fill​(double[][][] array3d, double value)
      Fills array3d with value. Not to be confused with fill(double[][], double), which fills a 2D array instead of a 3D one, or with fill(double, int, int), which makes a new 2D array.
      Parameters:
      array3d - a 3D array that will be modified in-place
      value - the value to fill all of array3d with
    • fill

      public static void fill​(int[][] array2d, int value)
      Fills array2d with value. Not to be confused with fill(int, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
    • fill

      public static void fill​(byte[][] array2d, byte value)
      Fills array2d with value. Not to be confused with fill(byte, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
    • fill

      public static void fill​(boolean[][] array2d, boolean value, int startX, int startY, int endX, int endY)
      Fills a sub-section of array2d with value, with the section defined by start/end x/y. Not to be confused with fill(boolean, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
      startX - the first x position to fill (inclusive)
      startY - the first y position to fill (inclusive)
      endX - the last x position to fill (inclusive)
      endY - the last y position to fill (inclusive)
    • fill

      public static void fill​(char[][] array2d, char value, int startX, int startY, int endX, int endY)
      Fills a sub-section of array2d with value, with the section defined by start/end x/y. Not to be confused with fill(char, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
      startX - the first x position to fill (inclusive)
      startY - the first y position to fill (inclusive)
      endX - the last x position to fill (inclusive)
      endY - the last y position to fill (inclusive)
    • fill

      public static void fill​(float[][] array2d, float value, int startX, int startY, int endX, int endY)
      Fills a sub-section of array2d with value, with the section defined by start/end x/y. Not to be confused with fill(float, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
      startX - the first x position to fill (inclusive)
      startY - the first y position to fill (inclusive)
      endX - the last x position to fill (inclusive)
      endY - the last y position to fill (inclusive)
    • fill

      public static void fill​(double[][] array2d, double value, int startX, int startY, int endX, int endY)
      Fills a sub-section of array2d with value, with the section defined by start/end x/y. Not to be confused with fill(double, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
      startX - the first x position to fill (inclusive)
      startY - the first y position to fill (inclusive)
      endX - the last x position to fill (inclusive)
      endY - the last y position to fill (inclusive)
    • fill

      public static void fill​(int[][] array2d, int value, int startX, int startY, int endX, int endY)
      Fills a sub-section of array2d with value, with the section defined by start/end x/y. Not to be confused with fill(int, int, int), which makes a new 2D array.
      Parameters:
      array2d - a 2D array that will be modified in-place
      value - the value to fill all of array2D with
      startX - the first x position to fill (inclusive)
      startY - the first y position to fill (inclusive)
      endX - the last x position to fill (inclusive)
      endY - the last y position to fill (inclusive)
    • randomFill

      public static void randomFill​(long[][] array2d, long seed)
      Randomly fills all of array2d with random values generated from seed; can fill an element with any long, positive or negative. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      seed - the seed for the random values, as a long
    • randomFill

      public static void randomFill​(int[][] array2d, long seed)
      Randomly fills all of array2d with random values generated from seed; can fill an element with any int, positive or negative. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      seed - the seed for the random values, as a long
    • randomFill

      public static void randomFill​(int[][] array2d, int bound, long seed)
      Randomly fills all of array2d with random values generated from seed, limiting results to between 0 and bound, exclusive. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      bound - the upper exclusive limit for the ints this can produce
      seed - the seed for the random values, as a long
    • randomFill

      public static void randomFill​(char[][] array2d, char[] values, long seed)
      Randomly fills all of array2d with random values generated from seed, choosing chars to place in the given 2D array by selecting them at random from the given 1D char array values. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      values - a 1D char array containing the possible char values that can be chosen to fill array2d
      seed - the seed for the random values, as a long
    • randomFill

      public static void randomFill​(char[][] array2d, CharSequence values, long seed)
      Randomly fills all of array2d with random values generated from seed, choosing chars to place in the given 2D array by selecting them at random from the given 1D char array values. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      values - a 1D char array containing the possible char values that can be chosen to fill array2d
      seed - the seed for the random values, as a long
    • randomFill

      public static void randomFill​(float[][] array2d, long seed)
      Randomly fills all of array2d with random values generated from seed; can fill an element with any float between 0.0 inclusive and 1.0 exclusive. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      seed - the seed for the random values, as a long
    • randomFill

      public static void randomFill​(float[][] array2d, float bound, long seed)
      Randomly fills all of array2d with random values generated from seed, limiting results to between 0 and bound, exclusive. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      bound - the upper exclusive limit for the floats this can produce
      seed - the seed for the random values, as a long
    • randomFill

      public static void randomFill​(double[][] array2d, long seed)
      Randomly fills all of array2d with random values generated from seed; can fill an element with any double between 0.0 inclusive and 1.0 exclusive. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      seed - the seed for the random values, as a long
    • randomFill

      public static void randomFill​(double[][] array2d, double bound, long seed)
      Randomly fills all of array2d with random values generated from seed, limiting results to between 0 and bound, exclusive. Fairly efficient; uses a fast random number generation algorithm that can avoid some unnecessary work in this context, and improves quality by seeding each column differently. Generates (height + 1) * width random values to fill the height * width elements in array2d.
      Parameters:
      array2d - a 2D array that will be modified in-place
      bound - the upper exclusive limit for the doubles this can produce
      seed - the seed for the random values, as a long
    • reorder

      public static <T> ArrayList<T> reorder​(ArrayList<T> list, int... ordering)
      Rearranges an ArrayList to use the given ordering, returning a copy; random orderings can be produced with RNG.randomOrdering(int) or RNG.randomOrdering(int, int[]). These orderings will never repeat an earlier element, and the returned ArrayList may be shorter than the original if ordering isn't as long as list. Using a random ordering is like shuffling, but allows you to repeat the shuffle exactly on other collections of the same size. A reordering can also be inverted with invertOrdering(int[]) or invertOrdering(int[], int[]), getting the change that will undo another ordering.
      Type Parameters:
      T - any generic type
      Parameters:
      list - an ArrayList that you want a reordered version of; will not be modified.
      ordering - an ordering, typically produced by one of RNG's randomOrdering methods.
      Returns:
      a modified copy of list with its ordering changed to match ordering.
    • invertOrdering

      public static int[] invertOrdering​(int[] ordering)
      Given an ordering such as one produced by RNG.randomOrdering(int, int[]), this finds its inverse, able to reverse the reordering and vice versa.
      Parameters:
      ordering - the ordering to find the inverse for
      Returns:
      the inverse of ordering
    • invertOrdering

      public static int[] invertOrdering​(int[] ordering, int[] dest)
      Given an ordering such as one produced by RNG.randomOrdering(int, int[]), this finds its inverse, able to reverse the reordering and vice versa. This overload doesn't allocate a new int array, and instead relies on having an int array of the same size as ordering passed to it as an additional argument.
      Parameters:
      ordering - the ordering to find the inverse for
      dest - the int array to put the inverse reordering into; should have the same length as ordering
      Returns:
      the inverse of ordering; will have the same value as dest
    • reverse

      public static boolean[] reverse​(boolean[] data)
      Reverses the array given as a parameter, in-place, and returns the modified original.
      Parameters:
      data - an array that will be reversed in-place
      Returns:
      the array passed in, after reversal
    • reverse

      public static char[] reverse​(char[] data)
      Reverses the array given as a parameter, in-place, and returns the modified original.
      Parameters:
      data - an array that will be reversed in-place
      Returns:
      the array passed in, after reversal
    • reverse

      public static float[] reverse​(float[] data)
      Reverses the array given as a parameter, in-place, and returns the modified original.
      Parameters:
      data - an array that will be reversed in-place
      Returns:
      the array passed in, after reversal
    • reverse

      public static double[] reverse​(double[] data)
      Reverses the array given as a parameter, in-place, and returns the modified original.
      Parameters:
      data - an array that will be reversed in-place
      Returns:
      the array passed in, after reversal
    • reverse

      public static int[] reverse​(int[] data)
      Reverses the array given as a parameter, in-place, and returns the modified original.
      Parameters:
      data - an array that will be reversed in-place
      Returns:
      the array passed in, after reversal
    • reverse

      public static byte[] reverse​(byte[] data)
      Reverses the array given as a parameter, in-place, and returns the modified original.
      Parameters:
      data - an array that will be reversed in-place
      Returns:
      the array passed in, after reversal
    • reverse

      public static <T> T[] reverse​(T[] data)
      Reverses the array given as a parameter, in-place, and returns the modified original.
      Parameters:
      data - an array that will be reversed in-place
      Returns:
      the array passed in, after reversal