org.apache.commons.lang3

## Class RandomUtils

- java.lang.Object
- - org.apache.commons.lang3.RandomUtils

- Deprecated.
  Use Apache Commons RNG's optimized UniformRandomProvider

      @Deprecated
      public class RandomUtils
      extends Object

  Utility library that supplements the standard `Random` class.

  Caveat: Instances of `Random` are not cryptographically secure.

  Please note that the Apache Commons project provides a component dedicated to pseudo-random number generation, namely Commons RNG, that may be a better choice for applications with more stringent requirements (performance and/or correctness).

  Since:
    3.3

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RandomUtils()` Deprecated. `RandomUtils` instances should NOT be constructed in standard programming.

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `nextBoolean()` Deprecated. Generates a random boolean value.
    `static byte[]` | `nextBytes(int count)` Deprecated. Generates an array of random bytes.
    `static double` | `nextDouble()` Deprecated. Generates a random double within 0 - Double.MAX_VALUE.
    `static double` | `nextDouble(double startInclusive, double endExclusive)` Deprecated. Generates a random double within the specified range.
    `static float` | `nextFloat()` Deprecated. Generates a random float within 0 - Float.MAX_VALUE.
    `static float` | `nextFloat(float startInclusive, float endExclusive)` Deprecated. Generates a random float within the specified range.
    `static int` | `nextInt()` Deprecated. Generates a random int within 0 - Integer.MAX_VALUE.
    `static int` | `nextInt(int startInclusive, int endExclusive)` Deprecated. Generates a random integer within the specified range.
    `static long` | `nextLong()` Deprecated. Generates a random long within 0 - Long.MAX_VALUE.
    `static long` | `nextLong(long startInclusive, long endExclusive)` Deprecated. Generates a random long within the specified range.

    - ### Methods inherited from class java.lang.Object

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

- - ### Constructor Detail

    - #### RandomUtils

          public RandomUtils()

      Deprecated.
      `RandomUtils` instances should NOT be constructed in standard programming. Instead, the class should be used as `RandomUtils.nextBytes(5);`.

      This constructor is public to permit tools that require a JavaBean instance to operate.

  - ### Method Detail

    - #### nextBoolean

          public static boolean nextBoolean()

      Deprecated.
      Generates a random boolean value.
      Returns:
        the random boolean
      Since:
        3.5

    - #### nextBytes

          public static byte[] nextBytes(int count)

      Deprecated.
      Generates an array of random bytes.
      Parameters:
        `count` - the size of the returned array
      Returns:
        the random byte array
      Throws:
        `IllegalArgumentException` - if `count` is negative

    - #### nextDouble

          public static double nextDouble()

      Deprecated.
      Generates a random double within 0 - Double.MAX_VALUE.
      Returns:
        the random double
      Since:
        3.5
      See Also:
        `nextDouble(double, double)`

    - #### nextDouble

          public static double nextDouble(double startInclusive,
                                          double endExclusive)

      Deprecated.
      Generates a random double within the specified range.
      Parameters:
        `startInclusive` - the smallest value that can be returned, must be non-negative
        `endExclusive` - the upper bound (not included)
      Returns:
        the random double
      Throws:
        `IllegalArgumentException` - if `startInclusive > endExclusive` or if `startInclusive` is negative

    - #### nextFloat

          public static float nextFloat()

      Deprecated.
      Generates a random float within 0 - Float.MAX_VALUE.
      Returns:
        the random float
      Since:
        3.5
      See Also:
        `nextFloat(float, float)`

    - #### nextFloat

          public static float nextFloat(float startInclusive,
                                        float endExclusive)

      Deprecated.
      Generates a random float within the specified range.
      Parameters:
        `startInclusive` - the smallest value that can be returned, must be non-negative
        `endExclusive` - the upper bound (not included)
      Returns:
        the random float
      Throws:
        `IllegalArgumentException` - if `startInclusive > endExclusive` or if `startInclusive` is negative

    - #### nextInt

          public static int nextInt()

      Deprecated.
      Generates a random int within 0 - Integer.MAX_VALUE.
      Returns:
        the random integer
      Since:
        3.5
      See Also:
        `nextInt(int, int)`

    - #### nextInt

          public static int nextInt(int startInclusive,
                                    int endExclusive)

      Deprecated.
      Generates a random integer within the specified range.
      Parameters:
        `startInclusive` - the smallest value that can be returned, must be non-negative
        `endExclusive` - the upper bound (not included)
      Returns:
        the random integer
      Throws:
        `IllegalArgumentException` - if `startInclusive > endExclusive` or if `startInclusive` is negative

    - #### nextLong

          public static long nextLong()

      Deprecated.
      Generates a random long within 0 - Long.MAX_VALUE.
      Returns:
        the random long
      Since:
        3.5
      See Also:
        `nextLong(long, long)`

    - #### nextLong

          public static long nextLong(long startInclusive,
                                      long endExclusive)

      Deprecated.
      Generates a random long within the specified range.
      Parameters:
        `startInclusive` - the smallest value that can be returned, must be non-negative
        `endExclusive` - the upper bound (not included)
      Returns:
        the random long
      Throws:
        `IllegalArgumentException` - if `startInclusive > endExclusive` or if `startInclusive` is negative

Copyright © 2001–2023 The Apache Software Foundation. All rights reserved.