com.h3c.util

## Class RandomUtils

- java.lang.Object
- - com.h3c.util.RandomUtils

-     public final class RandomUtils
      extends Object

  Provides useful utilities revolving around randomness.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `intFromRange(int low, int high)` Selects an integer at random, bounded by the specified range of low (inclusive) to high (exclusive).
    `static <T> T` | `select(List<T> choices)` Randomly selects and returns one item from the given list.

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

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

- - ### Method Detail

    - #### select

          public static <T> T select(List<T> choices)

      Randomly selects and returns one item from the given list.
      Type Parameters:
        `T` - the item type
      Parameters:
        `choices` - the list of choices
      Returns:
        a randomly selected item
      Throws:
        `NullPointerException` - if the parameter is null
        `IllegalArgumentException` - if the parameter is an empty list

    - #### intFromRange

          public static int intFromRange(int low,
                         int high)

      Selects an integer at random, bounded by the specified range of low (inclusive) to high (exclusive). `low` must be greater or equal to zero; `high` must be greater than `low`. For example, invoking the following:

                int r = RandomUtils.intFromRange(5, 10);

      will randomly return one of `5, 6, 7, 8, 9`.
      Parameters:
        `low` - the lowest value (inclusive)
        `high` - the highest value (exclusive)
      Returns:
        an int from within the given range
      Throws:
        `IllegalArgumentException` - if low < 0 or high <= low

Copyright © 2014. All Rights Reserved.