Class Enhanced32Random

java.lang.Object
java.util.Random
com.github.tommyettinger.random.EnhancedRandom
com.github.tommyettinger.random.Enhanced32Random
All Implemented Interfaces:
Externalizable, Serializable, RandomGenerator
Direct Known Subclasses:
Bear32Random, Chill32Random, Chip32Random, Choo32Random, ChopRandom, Jsf32Random, Lamb32Random, Respite32Random, Taxon32Random, Xoshiro128PlusPlusRandom, Xoshiro160RoadroxoRandom

public abstract class Enhanced32Random extends EnhancedRandom
A specialized subclass of EnhancedRandom meant for generators that use 32-bit math and natively operate on int results instead of long results.
See Also:
  • Nested Class Summary

  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Enhanced32Random(long seed)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if this generator mainly operates via its nextInt() method internally, which means its nextLong() must generate two int values instead of naturally producing one long.
    double
    maxDoubleOf(double innerBound, double outerBound, int trials)
    Returns the maximum result of trials calls to nextDouble(double, double) using the given innerBound and outerBound.
    float
    maxFloatOf(float innerBound, float outerBound, int trials)
    Returns the maximum result of trials calls to nextFloat(float, float) using the given innerBound and outerBound.
    int
    maxIntOf(int innerBound, int outerBound, int trials)
    Returns the maximum result of trials calls to nextSignedInt(int, int) using the given innerBound and outerBound.
    long
    maxLongOf(long innerBound, long outerBound, int trials)
    Returns the maximum result of trials calls to nextSignedLong(long, long) using the given innerBound and outerBound.
    double
    minDoubleOf(double innerBound, double outerBound, int trials)
    Returns the minimum result of trials calls to nextDouble(double, double) using the given innerBound and outerBound.
    float
    minFloatOf(float innerBound, float outerBound, int trials)
    Returns the minimum result of trials calls to nextFloat(float, float) using the given innerBound and outerBound.
    int
    minIntOf(int innerBound, int outerBound, int trials)
    Returns the minimum result of trials calls to nextSignedInt(int, int) using the given innerBound and outerBound.
    long
    minLongOf(long innerBound, long outerBound, int trials)
    Returns the minimum result of trials calls to nextSignedLong(long, long) using the given innerBound and outerBound.
    int
    next(int bits)
    Generates the next pseudorandom number with a specific maximum size in bits (not a max number).
    boolean
    Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
    boolean
    nextBoolean(float chance)
    Returns true if a random value between 0 and 1 is less than the specified value.
    void
    nextBytes(byte[] bytes)
    Generates random bytes and places them into a user-supplied byte array.
    double
    Returns the next pseudorandom, uniformly distributed double value between 0.0 (inclusive) and 1.0 (exclusive) from this random number generator's sequence.
    double
    nextDouble(double outerBound)
    Gets a pseudo-random double between 0 (inclusive) and outerBound (exclusive).
    double
    nextDouble(double innerBound, double outerBound)
    Gets a pseudo-random double between innerBound (inclusive) and outerBound (exclusive).
    double
    Gets a random double between 0.0 and 1.0, exclusive at both ends; this method is also more uniform than nextDouble() if you use the bit-patterns of the returned doubles.
    double
    nextExclusiveDouble(double outerBound)
    Just like nextDouble(double), but this is exclusive on both 0.0 and outerBound.
    double
    nextExclusiveDouble(double innerBound, double outerBound)
    Just like nextDouble(double, double), but this is exclusive on both innerBound and outerBound.
    double
    Gets a random double between 0.0 and 1.0, exclusive at both ends.
    float
    Gets a random float between 0.0 and 1.0, exclusive at both ends.
    float
    nextExclusiveFloat(float outerBound)
    Just like nextFloat(float), but this is exclusive on both 0.0 and outerBound.
    float
    nextExclusiveFloat(float innerBound, float outerBound)
    Just like nextFloat(float, float), but this is exclusive on both innerBound and outerBound.
    float
    Gets a random float between 0.0 and 1.0, exclusive at both ends.
    double
    Gets a random double that may be positive or negative, but cannot be 0, and always has a magnitude less than 1.
    float
    Gets a random float that may be positive or negative, but cannot be 0, and always has a magnitude less than 1.
    double
    Returns a non-negative double value pseudorandomly chosen from an exponential distribution whose mean is 1.
    float
    Returns the next pseudorandom, uniformly distributed float value between 0.0 (inclusive) and 1.0 (exclusive) from this random number generator's sequence.
    float
    nextFloat(float outerBound)
    Gets a pseudo-random float between 0 (inclusive) and outerBound (exclusive).
    float
    nextFloat(float innerBound, float outerBound)
    Gets a pseudo-random float between innerBound (inclusive) and outerBound (exclusive).
    double
    Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
    double
    nextGaussian(double mean, double stddev)
    Returns the next pseudorandom, Gaussian ("normally") distributed double value with the specified mean and standard deviation from this random number generator's sequence.
    float
    Returns the next pseudorandom, Gaussian ("normally") distributed float value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
    float
    nextGaussianFloat(float mean, float stddev)
    Returns the next pseudorandom, Gaussian ("normally") distributed float value with the specified mean and standard deviation from this random number generator's sequence.
    double
    This is just like nextDouble(), returning a double between 0 and 1, except that it is inclusive on both 0.0 and 1.0.
    double
    nextInclusiveDouble(double outerBound)
    Just like nextDouble(double), but this is inclusive on both 0.0 and outerBound.
    double
    nextInclusiveDouble(double innerBound, double outerBound)
    Just like nextDouble(double, double), but this is inclusive on both innerBound and outerBound.
    float
    This is just like nextFloat(), returning a float between 0 and 1, except that it is inclusive on both 0.0 and 1.0.
    float
    nextInclusiveFloat(float outerBound)
    Just like nextFloat(float), but this is inclusive on both 0.0 and outerBound.
    float
    nextInclusiveFloat(float innerBound, float outerBound)
    Just like nextFloat(float, float), but this is inclusive on both innerBound and outerBound.
    int
    Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.
    int
    nextInt(int bound)
    Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
    int
    nextInt(int innerBound, int outerBound)
    Returns a pseudorandom, uniformly distributed int value between the specified innerBound (inclusive) and the specified outerBound (exclusive).
    long
    Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.
    long
    nextLong(long bound)
    Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
    long
    nextLong(long inner, long outer)
    Returns a pseudorandom, uniformly distributed long value between the specified innerBound (inclusive) and the specified outerBound (exclusive).
    int
    Returns -1 or 1, randomly.
    int
    nextSignedInt(int outerBound)
    Returns a pseudorandom, uniformly distributed int value between an inner bound of 0 (inclusive) and the specified outerBound (exclusive).
    int
    nextSignedInt(int innerBound, int outerBound)
    Returns a pseudorandom, uniformly distributed int value between the specified innerBound (inclusive) and the specified outerBound (exclusive).
    long
    nextSignedLong(long outerBound)
    Returns a pseudorandom, uniformly distributed long value between an inner bound of 0 (inclusive) and the specified outerBound (exclusive).
    long
    nextSignedLong(long inner, long outer)
    Returns a pseudorandom, uniformly distributed long value between the specified innerBound (inclusive) and the specified outerBound (exclusive).
    float
    Returns a triangularly distributed random number between -1.0 (exclusive) and 1.0 (exclusive), where values around zero are more likely.
    float
    nextTriangular(float max)
    Returns a triangularly distributed random number between -max (exclusive) and max (exclusive), where values around zero are more likely.
    float
    nextTriangular(float min, float max)
    Returns a triangularly distributed random number between min (inclusive) and max (exclusive), where the mode argument defaults to the midpoint between the bounds, giving a symmetric distribution.
    float
    nextTriangular(float min, float max, float mode)
    Returns a triangularly distributed random number between min (inclusive) and max (exclusive), where values around mode are more likely.
    int
    nextUnsignedInt(int bound)
    Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
    <T> T
    Gets a randomly selected item from the given List, such as an ArrayList.
    <T> T
    randomElement(T[] array)
    Gets a randomly-selected item from the given array, which must be non-null and non-empty
    void
    shuffle(boolean[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(boolean[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(byte[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(byte[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(char[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(char[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(double[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(double[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(float[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(float[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(int[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(int[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(long[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(long[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(short[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    void
    shuffle(short[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
    <T> void
    shuffle(List<T> items)
    Shuffles the given List in-place pseudo-randomly, using this to determine how to shuffle.
    <T> void
    shuffle(List<T> items, int offset, int length)
    Shuffles a section of the given List in-place pseudo-randomly, using this to determine how to shuffle.
    <T> void
    shuffle(T[] items)
    Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
    <T> void
    shuffle(T[] items, int offset, int length)
    Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.

    Methods inherited from class java.util.Random

    doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.random.RandomGenerator

    isDeprecated
  • Constructor Details

    • Enhanced32Random

      public Enhanced32Random()
    • Enhanced32Random

      public Enhanced32Random(long seed)
  • Method Details

    • mainlyGeneratesInt

      public boolean mainlyGeneratesInt()
      Returns true if this generator mainly operates via its nextInt() method internally, which means its nextLong() must generate two int values instead of naturally producing one long. This affects how the minimum period is measured for EnhancedRandom.getMinimumPeriod(). Most generators not intentionally targeting Google Web Toolkit mainly operate via nextLong() here, and return false. A generator that returns true here does not necessarily use 32-bit math; a generator can use 64-bit math internally but only produce 32 bits at a time by truncating its results.
      In Enhanced32Random, this returns true by default.
      Overrides:
      mainlyGeneratesInt in class EnhancedRandom
      Returns:
      true if measurements of the period measure calls to nextInt() instead of nextLong()
      See Also:
    • next

      public int next(int bits)
      Generates the next pseudorandom number with a specific maximum size in bits (not a max number). If you want to get a random number in a range, you should usually use nextInt(int) instead. For some specific cases, this method is more efficient and less biased than nextInt(int). For bits values between 1 and 30, this should be similar in effect to nextInt(1 << bits); though it won't typically produce the same values, they will have the correct range. If bits is 31, this can return any non-negative int; note that nextInt(1 << 31) won't behave this way because 1 << 31 is negative. If bits is 32 (or 0), this can return any int.

      The general contract of next is that it returns an int value and if the argument bits is between 1 and 32 (inclusive), then that many low-order bits of the returned value will be (approximately) independently chosen bit values, each of which is (approximately) equally likely to be 0 or 1.

      Note that you can give this values for bits that are outside its expected range of 1 to 32, but the value used, as long as bits is positive, will effectively be bits % 32. As stated before, a value of 0 for bits is the same as a value of 32.

      Overrides:
      next in class EnhancedRandom
      Parameters:
      bits - the amount of random bits to request, from 1 to 32
      Returns:
      the next pseudorandom value from this random number generator's sequence
    • nextBytes

      public void nextBytes(byte[] bytes)
      Generates random bytes and places them into a user-supplied byte array. The number of random bytes produced is equal to the length of the byte array.
      Specified by:
      nextBytes in interface RandomGenerator
      Overrides:
      nextBytes in class EnhancedRandom
      Parameters:
      bytes - the byte array to fill with random bytes
      Throws:
      NullPointerException - if the byte array is null
    • nextInt

      public int nextInt()
      Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence. The general contract of nextInt is that one int value is pseudorandomly generated and returned. All 232 possible int values are produced with (approximately) equal probability.
      In Enhanced32Random, this throws an UnsupportedOperationException because the concrete subclass must implement this.
      Specified by:
      nextInt in interface RandomGenerator
      Overrides:
      nextInt in class EnhancedRandom
      Returns:
      the next pseudorandom, uniformly distributed int value from this random number generator's sequence
    • nextInt

      public int nextInt(int bound)
      Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextInt is that one int value in the specified range is pseudorandomly generated and returned. All bound possible int values are produced with (approximately) equal probability.
      This method clamps bound to be at least 0; it never returns a negative int.
      It should be mentioned that the technique this uses has some bias, depending on bound, but it typically isn't measurable without specifically looking for it. Using the method this does allows this method to always advance the state by one step, instead of a varying and unpredictable amount with the more typical ways of rejection-sampling random numbers and only using numbers that can produce an int within the bound without bias. See M.E. O'Neill's blog about random numbers for discussion of alternative, unbiased methods.
      Specified by:
      nextInt in interface RandomGenerator
      Overrides:
      nextInt in class EnhancedRandom
      Parameters:
      bound - the upper bound (exclusive). If negative or 0, this always returns 0.
      Returns:
      the next pseudorandom, uniformly distributed int value between zero (inclusive) and bound (exclusive) from this random number generator's sequence
    • nextUnsignedInt

      public int nextUnsignedInt(int bound)
      Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextInt is that one int value in the specified range is pseudorandomly generated and returned. All bound possible int values are produced with (approximately) equal probability.
      This method treats the outer bound as unsigned, so if a negative int is passed as bound, it will be treated as positive and larger than Integer.MAX_VALUE. That means this can produce results that are positive or negative, but when you mask the result and the bound with 0xFFFFFFFFL (to treat them as unsigned), the result will always be between 0L (inclusive) and the masked bound (exclusive).
      This is primarily useful as a building block for other methods in this class.
      Overrides:
      nextUnsignedInt in class EnhancedRandom
      Parameters:
      bound - the upper bound (exclusive); treated as unsigned
      Returns:
      the next pseudorandom, uniformly distributed int value between zero (inclusive) and bound (exclusive), treated as unsigned, from this random number generator's sequence
    • nextSignedInt

      public int nextSignedInt(int outerBound)
      Returns a pseudorandom, uniformly distributed int value between an inner bound of 0 (inclusive) and the specified outerBound (exclusive). This is meant for cases where the outer bound may be negative, especially if the bound is unknown or may be user-specified. A negative outer bound is used as the lower bound; a positive outer bound is used as the upper bound. An outer bound of -1, 0, or 1 will always return 0, keeping the bound exclusive (except for outer bound 0). This method is slightly slower than nextInt(int).
      Overrides:
      nextSignedInt in class EnhancedRandom
      Parameters:
      outerBound - the outer exclusive bound; may be any int value, allowing negative
      Returns:
      a pseudorandom int between 0 (inclusive) and outerBound (exclusive)
      See Also:
    • nextInt

      public int nextInt(int innerBound, int outerBound)
      Returns a pseudorandom, uniformly distributed int value between the specified innerBound (inclusive) and the specified outerBound (exclusive). If outerBound is less than or equal to innerBound, this always returns innerBound.
      For any case where outerBound might be valid but less than innerBound, you can use nextSignedInt(int, int). If outerBound is less than innerBound here, this simply returns innerBound.
      Specified by:
      nextInt in interface RandomGenerator
      Overrides:
      nextInt in class EnhancedRandom
      Parameters:
      innerBound - the inclusive inner bound; may be any int, allowing negative
      outerBound - the exclusive outer bound; must be greater than innerBound (otherwise this returns innerBound)
      Returns:
      a pseudorandom int between innerBound (inclusive) and outerBound (exclusive)
      See Also:
    • nextSignedInt

      public int nextSignedInt(int innerBound, int outerBound)
      Returns a pseudorandom, uniformly distributed int value between the specified innerBound (inclusive) and the specified outerBound (exclusive). This is meant for cases where either bound may be negative, especially if the bounds are unknown or may be user-specified.
      Overrides:
      nextSignedInt in class EnhancedRandom
      Parameters:
      innerBound - the inclusive inner bound; may be any int, allowing negative
      outerBound - the exclusive outer bound; may be any int, allowing negative
      Returns:
      a pseudorandom int between innerBound (inclusive) and outerBound (exclusive)
      See Also:
    • nextLong

      public long nextLong()
      Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence. The general contract of nextLong is that one long value is pseudorandomly generated and returned.
      The only methods that need to be implemented by this interface are this and EnhancedRandom.copy(), though other methods can be implemented as appropriate for generators that, for instance, natively produce ints rather than longs.
      Specified by:
      nextLong in interface RandomGenerator
      Specified by:
      nextLong in class EnhancedRandom
      Returns:
      the next pseudorandom, uniformly distributed long value from this random number generator's sequence
    • nextLong

      public long nextLong(long bound)
      Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextLong is that one long value in the specified range is pseudorandomly generated and returned. All bound possible long values are produced with (approximately) equal probability, though there is a small amount of bias depending on the bound.
      Note that this advances the state by the same amount as a single call to nextLong(), which allows methods like EnhancedRandom.skip(long) to function correctly, but introduces some bias when bound is very large. This will also advance the state if bound is 0 or negative, so usage with a variable bound will advance the state reliably.
      This method has some bias, particularly on larger bounds. Actually measuring bias with bounds in the trillions or greater is challenging but not impossible, so don't use this for a real-money gambling purpose. The bias isn't especially significant, though.
      Specified by:
      nextLong in interface RandomGenerator
      Overrides:
      nextLong in class EnhancedRandom
      Parameters:
      bound - the upper bound (exclusive). If negative or 0, this always returns 0.
      Returns:
      the next pseudorandom, uniformly distributed long value between zero (inclusive) and bound (exclusive) from this random number generator's sequence
      See Also:
    • nextSignedLong

      public long nextSignedLong(long outerBound)
      Returns a pseudorandom, uniformly distributed long value between an inner bound of 0 (inclusive) and the specified outerBound (exclusive). This is meant for cases where the outer bound may be negative, especially if the bound is unknown or may be user-specified. A negative outer bound is used as the lower bound; a positive outer bound is used as the upper bound. An outer bound of -1, 0, or 1 will always return 0, keeping the bound exclusive (except for outer bound 0).

      Note that this advances the state by the same amount as a single call to nextLong(), which allows methods like EnhancedRandom.skip(long) to function correctly, but introduces some bias when bound is very large. This method should be about as fast as nextLong(long) , unlike the speed difference between nextInt(int) and nextSignedInt(int).

      Overrides:
      nextSignedLong in class EnhancedRandom
      Parameters:
      outerBound - the outer exclusive bound; may be any long value, allowing negative
      Returns:
      a pseudorandom long between 0 (inclusive) and outerBound (exclusive)
      See Also:
    • nextLong

      public long nextLong(long inner, long outer)
      Returns a pseudorandom, uniformly distributed long value between the specified innerBound (inclusive) and the specified outerBound (exclusive). If outerBound is less than or equal to innerBound, this always returns innerBound.
      For any case where outerBound might be valid but less than innerBound, you can use nextSignedLong(long, long).
      Specified by:
      nextLong in interface RandomGenerator
      Overrides:
      nextLong in class EnhancedRandom
      Parameters:
      inner - the inclusive inner bound; may be any long, allowing negative
      outer - the exclusive outer bound; must be greater than innerBound (otherwise this returns innerBound)
      Returns:
      a pseudorandom long between innerBound (inclusive) and outerBound (exclusive)
      See Also:
    • nextSignedLong

      public long nextSignedLong(long inner, long outer)
      Returns a pseudorandom, uniformly distributed long value between the specified innerBound (inclusive) and the specified outerBound (exclusive). This is meant for cases where either bound may be negative, especially if the bounds are unknown or may be user-specified.
      Overrides:
      nextSignedLong in class EnhancedRandom
      Parameters:
      inner - the inclusive inner bound; may be any long, allowing negative
      outer - the exclusive outer bound; may be any long, allowing negative
      Returns:
      a pseudorandom long between innerBound (inclusive) and outerBound (exclusive)
      See Also:
    • nextBoolean

      public boolean nextBoolean()
      Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence. The general contract of nextBoolean is that one boolean value is pseudorandomly generated and returned. The values true and false are produced with (approximately) equal probability.
      The public implementation simply returns a sign check on nextInt(), returning true if the generated int is negative. This is typically the safest way to implement this method; many types of generators have less statistical quality on their lowest bit, so just returning based on the lowest bit isn't always a good idea.
      Specified by:
      nextBoolean in interface RandomGenerator
      Overrides:
      nextBoolean in class EnhancedRandom
      Returns:
      the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence
    • nextFloat

      public float nextFloat()
      Returns the next pseudorandom, uniformly distributed float value between 0.0 (inclusive) and 1.0 (exclusive) from this random number generator's sequence.

      The general contract of nextFloat is that one float value, chosen (approximately) uniformly from the range 0.0f (inclusive) to 1.0f (exclusive), is pseudorandomly generated and returned. All 224 possible float values of the form m x 2-24, where m is a positive integer less than 224, are produced with (approximately) equal probability.

      The public implementation uses the upper 24 bits of nextLong(), with an unsigned right shift and a multiply by a very small float (5.9604645E-8f or 0x1p-24f). It tends to be fast if nextLong() is fast, but alternative implementations could use 24 bits of nextInt() (or just next(int), giving it 24) if that generator doesn't efficiently generate 64-bit longs.

      Specified by:
      nextFloat in interface RandomGenerator
      Overrides:
      nextFloat in class EnhancedRandom
      Returns:
      the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence
    • nextFloat

      public float nextFloat(float outerBound)
      Gets a pseudo-random float between 0 (inclusive) and outerBound (exclusive). The outerBound may be positive or negative. Exactly the same as nextFloat() * outerBound.
      Specified by:
      nextFloat in interface RandomGenerator
      Overrides:
      nextFloat in class EnhancedRandom
      Parameters:
      outerBound - the exclusive outer bound
      Returns:
      a float between 0 (inclusive) and outerBound (exclusive)
    • nextFloat

      public float nextFloat(float innerBound, float outerBound)
      Gets a pseudo-random float between innerBound (inclusive) and outerBound (exclusive). Either, neither, or both of innerBound and outerBound may be negative; this does not change which is inclusive and which is exclusive.
      Specified by:
      nextFloat in interface RandomGenerator
      Overrides:
      nextFloat in class EnhancedRandom
      Parameters:
      innerBound - the inclusive inner bound; may be negative
      outerBound - the exclusive outer bound; may be negative
      Returns:
      a float between innerBound (inclusive) and outerBound (exclusive)
    • nextDouble

      public double nextDouble()
      Returns the next pseudorandom, uniformly distributed double value between 0.0 (inclusive) and 1.0 (exclusive) from this random number generator's sequence.

      The general contract of nextDouble is that one double value, chosen (approximately) uniformly from the range 0.0d (inclusive) to 1.0d (exclusive), is pseudorandomly generated and returned.

      The public implementation uses the upper 53 bits of nextLong(), with an unsigned right shift and a multiply by a very small double (1.1102230246251565E-16, or 0x1p-53). It should perform well if nextLong() performs well, and is expected to perform less well if the generator naturally produces 32 or fewer bits at a time.

      Specified by:
      nextDouble in interface RandomGenerator
      Overrides:
      nextDouble in class EnhancedRandom
      Returns:
      the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence
    • nextDouble

      public double nextDouble(double outerBound)
      Gets a pseudo-random double between 0 (inclusive) and outerBound (exclusive). The outerBound may be positive or negative. Exactly the same as nextDouble() * outerBound.
      Specified by:
      nextDouble in interface RandomGenerator
      Overrides:
      nextDouble in class EnhancedRandom
      Parameters:
      outerBound - the exclusive outer bound
      Returns:
      a double between 0 (inclusive) and outerBound (exclusive)
    • nextDouble

      public double nextDouble(double innerBound, double outerBound)
      Gets a pseudo-random double between innerBound (inclusive) and outerBound (exclusive). Either, neither, or both of innerBound and outerBound may be negative; this does not change which is inclusive and which is exclusive.
      Specified by:
      nextDouble in interface RandomGenerator
      Overrides:
      nextDouble in class EnhancedRandom
      Parameters:
      innerBound - the inclusive inner bound; may be negative
      outerBound - the exclusive outer bound; may be negative
      Returns:
      a double between innerBound (inclusive) and outerBound (exclusive)
    • nextInclusiveDouble

      public double nextInclusiveDouble()
      This is just like nextDouble(), returning a double between 0 and 1, except that it is inclusive on both 0.0 and 1.0. It returns 1.0 rarely, 0.000000000000000005421010862427522% of the time if there is no bias in the generator, but it can happen.
      This method does not return purely-equidistant doubles, because there the resolution of possible doubles it can generate is higher as it approaches 0.0 . The smallest non-zero double this can return is 2.710505431213763e-20 (0x1.0000000000003p-65 in hex), and the largest non-one double this can return is 0.9999999999999999 (0x1.fffffffffffffp-1 in hex). This uses nearly identical code to nextExclusiveDouble(), but does some really unusual operations on both the bits and the double value to be able to produce 0.0 and 1.0 . This retains the exclusive version's quality of having approximately uniform distributions for every mantissa bit, unlike most ways of generating random floating-point numbers.
      Overrides:
      nextInclusiveDouble in class EnhancedRandom
      Returns:
      a double between 0.0, inclusive, and 1.0, inclusive
    • nextInclusiveDouble

      public double nextInclusiveDouble(double outerBound)
      Just like nextDouble(double), but this is inclusive on both 0.0 and outerBound. It may be important to note that it returns outerBound on only 0.000000000000011102230246251565% of calls.
      Overrides:
      nextInclusiveDouble in class EnhancedRandom
      Parameters:
      outerBound - the outer inclusive bound; may be positive or negative
      Returns:
      a double between 0.0, inclusive, and outerBound, inclusive
    • nextInclusiveDouble

      public double nextInclusiveDouble(double innerBound, double outerBound)
      Just like nextDouble(double, double), but this is inclusive on both innerBound and outerBound. It may be important to note that it returns outerBound on only 0.000000000000011102230246251565% of calls, if it can return it at all because of floating-point imprecision when innerBound is a larger number.
      Overrides:
      nextInclusiveDouble in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer inclusive bound; may be positive or negative
      Returns:
      a double between innerBound, inclusive, and outerBound, inclusive
    • nextInclusiveFloat

      public float nextInclusiveFloat()
      This is just like nextFloat(), returning a float between 0 and 1, except that it is inclusive on both 0.0 and 1.0.
      Overrides:
      nextInclusiveFloat in class EnhancedRandom
      Returns:
      a float between 0.0, inclusive, and 1.0, inclusive
    • nextInclusiveFloat

      public float nextInclusiveFloat(float outerBound)
      Just like nextFloat(float), but this is inclusive on both 0.0 and outerBound. It may be important to note that it returns outerBound on only 0.00000596046412226771% of calls.
      Overrides:
      nextInclusiveFloat in class EnhancedRandom
      Parameters:
      outerBound - the outer inclusive bound; may be positive or negative
      Returns:
      a float between 0.0, inclusive, and outerBound, inclusive
    • nextInclusiveFloat

      public float nextInclusiveFloat(float innerBound, float outerBound)
      Just like nextFloat(float, float), but this is inclusive on both innerBound and outerBound. It may be important to note that it returns outerBound on only 0.00000596046412226771% of calls, if it can return it at all because of floating-point imprecision when innerBound is a larger number.
      Overrides:
      nextInclusiveFloat in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer inclusive bound; may be positive or negative
      Returns:
      a float between innerBound, inclusive, and outerBound, inclusive
    • nextExclusiveDouble

      public double nextExclusiveDouble()
      Gets a random double between 0.0 and 1.0, exclusive at both ends; this method is also more uniform than nextDouble() if you use the bit-patterns of the returned doubles. This is a simplified version of this algorithm by Allen Downey. This can return double values between 2.710505431213761E-20 and 0.9999999999999999, or 0x1.0p-65 and 0x1.fffffffffffffp-1 in hex notation. It cannot return 0 or 1. Some cases can prefer nextExclusiveDoubleEquidistant(), which is implemented more traditionally but may have slower performance. This method can also return doubles that are extremely close to 0, but can't return doubles that are as close to 1, due to how floating-point numbers work. However, nextExclusiveDoubleEquidistant() can return only a minimum value that is as distant from 0 as its maximum value is distant from 1.
      To compare, nextDouble() and nextExclusiveDoubleEquidistant() are less likely to produce a "1" bit for their lowest 5 bits of mantissa/significand (the least significant bits numerically, but potentially important for some uses), with the least significant bit produced half as often as the most significant bit in the mantissa. As for this method, it has approximately the same likelihood of producing a "1" bit for any position in the mantissa.
      The implementation may have different performance characteristics than nextDouble(), because this doesn't perform any floating-point multiplication or division, and instead assembles bits obtained by one call to nextLong(). This uses BitConversion.longBitsToDouble(long) and BitConversion.countLeadingZeros(long), both of which typically have optimized intrinsics on HotSpot, and this is branchless and loopless, unlike the original algorithm by Allen Downey. When compared with nextExclusiveDoubleEquidistant(), this method performs better on at least HotSpot JVMs. On GraalVM 17, this is over twice as fast as nextExclusiveDoubleEquidistant().
      Overrides:
      nextExclusiveDouble in class EnhancedRandom
      Returns:
      a random uniform double between 2.710505431213761E-20 and 0.9999999999999999 (both inclusive)
    • nextExclusiveDoubleEquidistant

      public double nextExclusiveDoubleEquidistant()
      Gets a random double between 0.0 and 1.0, exclusive at both ends. This can return double values between 1.1102230246251565E-16 and 0.9999999999999999, or 0x1.0p-53 and 0x1.fffffffffffffp-1 in hex notation. It cannot return 0 or 1, and its minimum and maximum results are equally distant from 0 and from 1, respectively. Many usages may prefer nextExclusiveDouble(), which is better-distributed if you consider the bit representation of the returned doubles, tends to perform better, and can return doubles that much closer to 0 than this can.
      The implementation simply uses nextLong(long) to get a uniformly-chosen long between 1 and (2 to the 53) - 1, both inclusive, and multiplies it by (2 to the -53). Using larger values than (2 to the 53) would cause issues with the double math.
      Overrides:
      nextExclusiveDoubleEquidistant in class EnhancedRandom
      Returns:
      a random uniform double between 0 and 1 (both exclusive)
    • nextExclusiveDouble

      public double nextExclusiveDouble(double outerBound)
      Just like nextDouble(double), but this is exclusive on both 0.0 and outerBound. Like nextExclusiveDouble(), which this uses, this may have better bit-distribution of double values, and it may also be better able to produce very small doubles when outerBound is large. It should typically be a little faster than nextDouble(double).
      Overrides:
      nextExclusiveDouble in class EnhancedRandom
      Parameters:
      outerBound - the outer exclusive bound; may be positive or negative
      Returns:
      a double between 0.0, exclusive, and outerBound, exclusive
    • nextExclusiveDouble

      public double nextExclusiveDouble(double innerBound, double outerBound)
      Just like nextDouble(double, double), but this is exclusive on both innerBound and outerBound. Like nextExclusiveDouble(), which this uses,, this may have better bit-distribution of double values, and it may also be better able to produce doubles close to innerBound when outerBound - innerBound is large. It should typically be a little faster than nextDouble(double, double).
      Overrides:
      nextExclusiveDouble in class EnhancedRandom
      Parameters:
      innerBound - the inner exclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      Returns:
      a double between innerBound, exclusive, and outerBound, exclusive
    • nextExclusiveSignedDouble

      public double nextExclusiveSignedDouble()
      Gets a random double that may be positive or negative, but cannot be 0, and always has a magnitude less than 1.
      This is a modified version of this algorithm by Allen Downey. This version can return double values between -0.9999999999999999 and -5.421010862427522E-20, as well as between 5.421010862427522E-20 and 0.9999999999999999, or -0x1.fffffffffffffp-1 to -0x1.0p-64 as well as between 0x1.0p-64 and 0x1.fffffffffffffp-1 in hex notation. It cannot return -1, 0 or 1. It has much more uniform bit distribution across its mantissa/significand bits than Random.nextDouble(), especially when the result of nextDouble() is expanded to the -1.0 to 1.0 range (such as with 2.0 * (nextDouble() - 0.5)). Where that code using nextDouble() is unable to produce a "1" bit for its lowest bit of mantissa (the least significant bits numerically, but potentially important for some uses), this has approximately the same likelihood of producing a "1" bit for any positions in the mantissa, and also equal odds for the sign bit.
      Some useful properties here are that this produces a negative result exactly as often as the underlying generator produces a negative result with nextLong(), and the least-significant bits that the underlying generator produces with nextLong() are also the least-significant in magnitude here. This could be used with lower-quality randomness, like a linear congruential generator, and the flaws those have with their low-order bits would barely affect floating-point results here. This generator also produces results that are symmetrical around 0.0, with every possible positive number having a possible negative number of equal magnitude, if the underlying generator is at least 1-dimensionally equidistributed. Note that generators such as Xoroshiro128StarStarRandom and Xoshiro256StarStarRandom cannot return 0L from nextLong() as frequently as other results, so this is not (technically) true of those. Those generators (and other LFSR-type generators) will produce 5.421010862427522E-20 less frequently than -5.421010862427522E-20 .
      Overrides:
      nextExclusiveSignedDouble in class EnhancedRandom
      Returns:
      a random uniform double between -1 and 1 with a tiny hole around 0 (all exclusive)
    • nextExclusiveFloat

      public float nextExclusiveFloat()
      Gets a random float between 0.0 and 1.0, exclusive at both ends. This method is also more uniform than nextFloat() if you use the bit-patterns of the returned floats. This is a simplified version of this algorithm by Allen Downey. This version can return float values between 2.7105054E-20 to 0.99999994, or 0x1.0p-65 to 0x1.fffffep-1 in hex notation. It cannot return 0 or 1. To compare, nextFloat() is less likely to produce a "1" bit for its lowest 5 bits of mantissa/significand (the least significant bits numerically, but potentially important for some uses), with the least significant bit produced half as often as the most significant bit in the mantissa. As for this method, it has approximately the same likelihood of producing a "1" bit for any position in the mantissa.
      The implementation may have different performance characteristics than nextFloat(), because this doesn't perform any floating-point multiplication or division, and instead assembles bits obtained by two calls to nextInt(). This uses BitConversion.intBitsToFloat(int) and BitConversion.countLeadingZeros(long), both of which typically have optimized intrinsics on HotSpot, and this is branchless and loopless, unlike the original algorithm by Allen Downey.
      Overrides:
      nextExclusiveFloat in class EnhancedRandom
      Returns:
      a random uniform float between 0 and 1 (both exclusive)
    • nextExclusiveFloatEquidistant

      public float nextExclusiveFloatEquidistant()
      Gets a random float between 0.0 and 1.0, exclusive at both ends. This can return float values between 5.9604645E-8 and 0.99999994, or 0x1.0p-24 and 0x1.fffffep-1 in hex notation. It cannot return 0 or 1, and its minimum and maximum results are equally distant from 0 and from 1, respectively. Most usages might prefer nextExclusiveFloat(), which is better-distributed if you consider the bit representation of the returned floats, tends to perform better, and can return floats that much closer to 0 than this can.
      The implementation simply uses nextInt(int) to get a uniformly-chosen int between 1 and (2 to the 24) - 1, both inclusive, and multiplies it by (2 to the -24). Using larger values than (2 to the 24) would cause issues with the float math.
      Overrides:
      nextExclusiveFloatEquidistant in class EnhancedRandom
      Returns:
      a random uniform float between 0 and 1 (both exclusive)
    • nextExclusiveFloat

      public float nextExclusiveFloat(float outerBound)
      Just like nextFloat(float), but this is exclusive on both 0.0 and outerBound. Like nextExclusiveFloat(), this may have better bit-distribution of float values, and it may also be better able to produce very small floats when outerBound is large. It should be a little faster than nextFloat(float).
      Overrides:
      nextExclusiveFloat in class EnhancedRandom
      Parameters:
      outerBound - the outer exclusive bound; may be positive or negative
      Returns:
      a float between 0.0, exclusive, and outerBound, exclusive
    • nextExclusiveFloat

      public float nextExclusiveFloat(float innerBound, float outerBound)
      Just like nextFloat(float, float), but this is exclusive on both innerBound and outerBound. Like nextExclusiveFloat(), this may have better bit-distribution of float values, and it may also be better able to produce floats close to innerBound when outerBound - innerBound is large. It should be a little faster than nextFloat(float, float).
      Overrides:
      nextExclusiveFloat in class EnhancedRandom
      Parameters:
      innerBound - the inner exclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      Returns:
      a float between innerBound, exclusive, and outerBound, exclusive
    • nextExclusiveSignedFloat

      public float nextExclusiveSignedFloat()
      Gets a random float that may be positive or negative, but cannot be 0, and always has a magnitude less than 1.
      This is a modified version of this algorithm by Allen Downey. This version can return float values between -0.99999994 and -5.421011E-20, as well as between 5.421011E-20 and 0.99999994, or -0x1.fffffep-1 to -0x1.0p-64 as well as between 0x1.0p-64 and 0x1.fffffep-1 in hex notation. It cannot return -1, 0 or 1. It has much more uniform bit distribution across its mantissa/significand bits than Random.nextFloat(), especially when the result of nextFloat() is expanded to the -1.0 to 1.0 range (such as with 2.0 * (nextFloat() - 0.5)). Where the given example code is unable to produce a "1" bit for its lowest bit of mantissa (the least significant bits numerically, but potentially important for some uses), this has approximately the same likelihood of producing a "1" bit for any positions in the mantissa, and also equal odds for the sign bit.
      This calls nextInt() twice.
      Overrides:
      nextExclusiveSignedFloat in class EnhancedRandom
      Returns:
      a random uniform float between -1 and 1 with a tiny hole around 0 (all exclusive)
    • nextGaussian

      public double nextGaussian()
      Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

      The general contract of nextGaussian is that one double value, chosen from (approximately) the usual normal distribution with mean 0.0 and standard deviation 1.0, is pseudorandomly generated and returned.

      This does not use a rough approximation, which is a departure from earlier versions; instead, it uses the Ziggurat method, which produces high-quality variables very quickly. Like earlier versions that used probit() or a bit-counting approximation, this requests exactly one long from the generator's sequence (using nextLong()). This makes it different from code like java.util.Random's nextGaussian() method, which can (rarely) fetch a higher number of random doubles.

      The implementation here was ported from code by Olaf Berstein, based on a paper by Jorgen A. Doornik and some steps from a paper by George Marsaglia. Distributor has more information, for the curious.

      Specified by:
      nextGaussian in interface RandomGenerator
      Overrides:
      nextGaussian in class EnhancedRandom
      Returns:
      the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence
    • nextGaussian

      public double nextGaussian(double mean, double stddev)
      Returns the next pseudorandom, Gaussian ("normally") distributed double value with the specified mean and standard deviation from this random number generator's sequence.
      This defaults to simply returning mean + stddev * nextGaussian().
      Specified by:
      nextGaussian in interface RandomGenerator
      Overrides:
      nextGaussian in class EnhancedRandom
      Parameters:
      mean - the mean of the Gaussian distribution to be drawn from
      stddev - the standard deviation (square root of the variance) of the Gaussian distribution to be drawn from
      Returns:
      a Gaussian distributed double with the specified mean and standard deviation
    • nextGaussianFloat

      public float nextGaussianFloat()
      Returns the next pseudorandom, Gaussian ("normally") distributed float value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

      The general contract of nextGaussianFloat is that one float value, chosen from (approximately) the usual normal distribution with mean 0.0 and standard deviation 1.0, is pseudorandomly generated and returned.

      This uses Distributor.probitI(int). Unlike nextGaussian(), this requests exactly one int from the generator's sequence (using nextInt()). This also makes it different from code like java.util.Random's nextGaussian() method, which can (rarely) fetch an arbitrarily higher number of random doubles.

      Overrides:
      nextGaussianFloat in class EnhancedRandom
      Returns:
      the next pseudorandom, Gaussian ("normally") distributed float value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence
    • nextGaussianFloat

      public float nextGaussianFloat(float mean, float stddev)
      Returns the next pseudorandom, Gaussian ("normally") distributed float value with the specified mean and standard deviation from this random number generator's sequence.
      This defaults to simply returning mean + stddev * nextGaussianFloat().
      Overrides:
      nextGaussianFloat in class EnhancedRandom
      Parameters:
      mean - the mean of the Gaussian distribution to be drawn from
      stddev - the standard deviation (square root of the variance) of the Gaussian distribution to be drawn from
      Returns:
      a Gaussian distributed float with the specified mean and standard deviation
    • nextExponential

      public double nextExponential()
      Returns a non-negative double value pseudorandomly chosen from an exponential distribution whose mean is 1.
      Specified by:
      nextExponential in interface RandomGenerator
      Overrides:
      nextExponential in class EnhancedRandom
      Returns:
      a non-negative double value pseudorandomly chosen from an exponential distribution with a mean of 1
    • nextBoolean

      public boolean nextBoolean(float chance)
      Returns true if a random value between 0 and 1 is less than the specified value.
      Overrides:
      nextBoolean in class EnhancedRandom
      Parameters:
      chance - a float between 0.0 and 1.0; higher values are more likely to result in true
      Returns:
      a boolean selected with the given chance of being true
    • nextSign

      public int nextSign()
      Returns -1 or 1, randomly.
      Overrides:
      nextSign in class EnhancedRandom
      Returns:
      -1 or 1, selected with approximately equal likelihood
    • nextTriangular

      public float nextTriangular()
      Returns a triangularly distributed random number between -1.0 (exclusive) and 1.0 (exclusive), where values around zero are more likely. Advances the state twice.

      This is an optimized version of nextTriangular(-1, 1, 0)

      Overrides:
      nextTriangular in class EnhancedRandom
    • nextTriangular

      public float nextTriangular(float max)
      Returns a triangularly distributed random number between -max (exclusive) and max (exclusive), where values around zero are more likely. Advances the state twice.

      This is an optimized version of nextTriangular(-max, max, 0)

      Overrides:
      nextTriangular in class EnhancedRandom
      Parameters:
      max - the upper limit
    • nextTriangular

      public float nextTriangular(float min, float max)
      Returns a triangularly distributed random number between min (inclusive) and max (exclusive), where the mode argument defaults to the midpoint between the bounds, giving a symmetric distribution. Advances the state once.

      This method is equivalent to nextTriangular(min, max, (min + max) * 0.5f)

      Overrides:
      nextTriangular in class EnhancedRandom
      Parameters:
      min - the lower limit
      max - the upper limit
    • nextTriangular

      public float nextTriangular(float min, float max, float mode)
      Returns a triangularly distributed random number between min (inclusive) and max (exclusive), where values around mode are more likely. Advances the state once.
      Overrides:
      nextTriangular in class EnhancedRandom
      Parameters:
      min - the lower limit
      max - the upper limit
      mode - the point around which the values are more likely
    • minIntOf

      public int minIntOf(int innerBound, int outerBound, int trials)
      Returns the minimum result of trials calls to nextSignedInt(int, int) using the given innerBound and outerBound. The innerBound is inclusive; the outerBound is exclusive. The higher trials is, the lower the average value this returns.
      Overrides:
      minIntOf in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      trials - how many random numbers to acquire and compare
      Returns:
      the lowest random number between innerBound (inclusive) and outerBound (exclusive) this found
    • maxIntOf

      public int maxIntOf(int innerBound, int outerBound, int trials)
      Returns the maximum result of trials calls to nextSignedInt(int, int) using the given innerBound and outerBound. The innerBound is inclusive; the outerBound is exclusive. The higher trials is, the higher the average value this returns.
      Overrides:
      maxIntOf in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      trials - how many random numbers to acquire and compare
      Returns:
      the highest random number between innerBound (inclusive) and outerBound (exclusive) this found
    • minLongOf

      public long minLongOf(long innerBound, long outerBound, int trials)
      Returns the minimum result of trials calls to nextSignedLong(long, long) using the given innerBound and outerBound. The innerBound is inclusive; the outerBound is exclusive. The higher trials is, the lower the average value this returns.
      Overrides:
      minLongOf in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      trials - how many random numbers to acquire and compare
      Returns:
      the lowest random number between innerBound (inclusive) and outerBound (exclusive) this found
    • maxLongOf

      public long maxLongOf(long innerBound, long outerBound, int trials)
      Returns the maximum result of trials calls to nextSignedLong(long, long) using the given innerBound and outerBound. The innerBound is inclusive; the outerBound is exclusive. The higher trials is, the higher the average value this returns.
      Overrides:
      maxLongOf in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      trials - how many random numbers to acquire and compare
      Returns:
      the highest random number between innerBound (inclusive) and outerBound (exclusive) this found
    • minDoubleOf

      public double minDoubleOf(double innerBound, double outerBound, int trials)
      Returns the minimum result of trials calls to nextDouble(double, double) using the given innerBound and outerBound. The innerBound is inclusive; the outerBound is exclusive. The higher trials is, the lower the average value this returns.
      Overrides:
      minDoubleOf in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      trials - how many random numbers to acquire and compare
      Returns:
      the lowest random number between innerBound (inclusive) and outerBound (exclusive) this found
    • maxDoubleOf

      public double maxDoubleOf(double innerBound, double outerBound, int trials)
      Returns the maximum result of trials calls to nextDouble(double, double) using the given innerBound and outerBound. The innerBound is inclusive; the outerBound is exclusive. The higher trials is, the higher the average value this returns.
      Overrides:
      maxDoubleOf in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      trials - how many random numbers to acquire and compare
      Returns:
      the highest random number between innerBound (inclusive) and outerBound (exclusive) this found
    • minFloatOf

      public float minFloatOf(float innerBound, float outerBound, int trials)
      Returns the minimum result of trials calls to nextFloat(float, float) using the given innerBound and outerBound. The innerBound is inclusive; the outerBound is exclusive. The higher trials is, the lower the average value this returns.
      Overrides:
      minFloatOf in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      trials - how many random numbers to acquire and compare
      Returns:
      the lowest random number between innerBound (inclusive) and outerBound (exclusive) this found
    • maxFloatOf

      public float maxFloatOf(float innerBound, float outerBound, int trials)
      Returns the maximum result of trials calls to nextFloat(float, float) using the given innerBound and outerBound. The innerBound is inclusive; the outerBound is exclusive. The higher trials is, the higher the average value this returns.
      Overrides:
      maxFloatOf in class EnhancedRandom
      Parameters:
      innerBound - the inner inclusive bound; may be positive or negative
      outerBound - the outer exclusive bound; may be positive or negative
      trials - how many random numbers to acquire and compare
      Returns:
      the highest random number between innerBound (inclusive) and outerBound (exclusive) this found
    • randomElement

      public <T> T randomElement(T[] array)
      Gets a randomly-selected item from the given array, which must be non-null and non-empty
      Overrides:
      randomElement in class EnhancedRandom
      Type Parameters:
      T - any reference type
      Parameters:
      array - a non-null, non-empty array of T items
      Returns:
      a random item from array
      Throws:
      NullPointerException - if array is null
      IndexOutOfBoundsException - if array is empty
    • randomElement

      public <T> T randomElement(List<T> list)
      Gets a randomly selected item from the given List, such as an ArrayList. If the List is empty, this throws an IndexOutOfBoundsException.
      Overrides:
      randomElement in class EnhancedRandom
      Type Parameters:
      T - the type of items
      Parameters:
      list - a non-empty implementation of List, such as ArrayList
      Returns:
      a randomly-selected item from list
    • shuffle

      public void shuffle(int[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - an int array; must be non-null
    • shuffle

      public void shuffle(int[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - an int array; must be non-null
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public void shuffle(long[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a long array; must be non-null
    • shuffle

      public void shuffle(long[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a long array; must be non-null
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public void shuffle(float[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a float array; must be non-null
    • shuffle

      public void shuffle(float[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a float array; must be non-null
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public void shuffle(char[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a char array; must be non-null
    • shuffle

      public void shuffle(char[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a char array; must be non-null
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public void shuffle(byte[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a byte array; must be non-null
    • shuffle

      public void shuffle(byte[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a byte array; must be non-null
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public void shuffle(double[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a double array; must be non-null
    • shuffle

      public void shuffle(double[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a double array; must be non-null
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public void shuffle(short[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a short array; must be non-null
    • shuffle

      public void shuffle(short[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a short array; must be non-null
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public void shuffle(boolean[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a boolean array; must be non-null
    • shuffle

      public void shuffle(boolean[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a boolean array; must be non-null
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public <T> void shuffle(T[] items)
      Shuffles the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - an array of some reference type; must be non-null but may contain null items
    • shuffle

      public <T> void shuffle(T[] items, int offset, int length)
      Shuffles a section of the given array in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - an array of some reference type; must be non-null but may contain null items
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle
    • shuffle

      public <T> void shuffle(List<T> items)
      Shuffles the given List in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a List of some type T; must be non-null but may contain null items
    • shuffle

      public <T> void shuffle(List<T> items, int offset, int length)
      Shuffles a section of the given List in-place pseudo-randomly, using this to determine how to shuffle.
      Overrides:
      shuffle in class EnhancedRandom
      Parameters:
      items - a List of some type T; must be non-null but may contain null items
      offset - the index of the first element of the array that can be shuffled
      length - the length of the section to shuffle