org.apache.commons.lang3

## Class RandomUtils

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

-     public class RandomUtils
      extends Object

  Utility library that supplements the standard `Random` class.

  Since:
    3.3
  Version:
    $Id: RandomUtils.java 1606051 2014-06-27 12:22:17Z ggregory $

- - ### Constructor Summary

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

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static byte[]` | `nextBytes(int count)` Creates an array of random bytes.
    `static double` | `nextDouble(double startInclusive, double endInclusive)` Returns a random double within the specified range.
    `static float` | `nextFloat(float startInclusive, float endInclusive)` Returns a random float within the specified range.
    `static int` | `nextInt(int startInclusive, int endExclusive)` Returns a random integer within the specified range.
    `static long` | `nextLong(long startInclusive, long endExclusive)` Returns 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()

      `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

    - #### nextBytes

          public static byte[] nextBytes(int count)

      Creates an array of random bytes.

      Parameters:
        `count` - the size of the returned array
      Returns:
        the random byte array
      Throws:
        `IllegalArgumentException` - if `count` is negative

    - #### nextInt

          public static int nextInt(int startInclusive,
                    int endExclusive)

      Returns 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(long startInclusive,
                      long endExclusive)

      Returns 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

    - #### nextDouble

          public static double nextDouble(double startInclusive,
                          double endInclusive)

      Returns a random double within the specified range.

      Parameters:
        `startInclusive` - the smallest value that can be returned, must be non-negative
        `endInclusive` - the upper bound (included)
      Returns:
        the random double
      Throws:
        `IllegalArgumentException` - if `startInclusive > endInclusive` or if `startInclusive` is negative

    - #### nextFloat

          public static float nextFloat(float startInclusive,
                        float endInclusive)

      Returns a random float within the specified range.

      Parameters:
        `startInclusive` - the smallest value that can be returned, must be non-negative
        `endInclusive` - the upper bound (included)
      Returns:
        the random float
      Throws:
        `IllegalArgumentException` - if `startInclusive > endInclusive` or if `startInclusive` is negative

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