Class RandomInteger

java.lang.Object
org.pipservices3.commons.random.RandomInteger

public class RandomInteger extends Object
Random generator for integer values.

### Example ###

 
 int value1 = RandomInteger.nextInteger(5, 10);     // Possible result: 7
 int value2 = RandomInteger.nextInteger(10);        // Possible result: 3
 int value3 = RandomInteger.updateInteger(10, 3);   // Possible result: 9
 
 
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    nextInteger(int max)
    Generates a integer in the range [0, 'max'].
    static int
    nextInteger(int min, int max)
    Generates a integer in the range ['min', 'max'].
    static List<Integer>
    sequence(int size)
    Generates a random sequence of integers starting from 0 like: [0,1,2,3...??]
    static List<Integer>
    sequence(int min, int max)
    Generates a random sequence of integers starting from 0 like: [0,1,2,3...??]
    static int
    updateInteger(int value)
    Updates (drifts) a integer value without specified range defined
    static int
    updateInteger(int value, int range)
    Updates (drifts) a integer value within specified range defined

    Methods inherited from class java.lang.Object

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

    • RandomInteger

      public RandomInteger()
  • Method Details

    • nextInteger

      public static int nextInteger(int max)
      Generates a integer in the range [0, 'max'].
      Parameters:
      max - (optional) maximum value of the integer that will be generated. Defaults to 'min' if omitted.
      Returns:
      generated random integer value.
    • nextInteger

      public static int nextInteger(int min, int max)
      Generates a integer in the range ['min', 'max']. If 'max' is omitted, then the range will be set to [0, 'min'].
      Parameters:
      min - minimum value of the integer that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.
      max - (optional) maximum value of the integer that will be generated. Defaults to 'min' if omitted.
      Returns:
      generated random integer value.
    • updateInteger

      public static int updateInteger(int value)
      Updates (drifts) a integer value without specified range defined
      Parameters:
      value - a integer value to drift.
      Returns:
      updated random integer value.
    • updateInteger

      public static int updateInteger(int value, int range)
      Updates (drifts) a integer value within specified range defined
      Parameters:
      value - a integer value to drift.
      range - (optional) a range. Default: 10% of the value
      Returns:
      updated random integer value.
    • sequence

      public static List<Integer> sequence(int size)
      Generates a random sequence of integers starting from 0 like: [0,1,2,3...??]
      Parameters:
      size - size of sequence
      Returns:
      generated array of integers.
    • sequence

      public static List<Integer> sequence(int min, int max)
      Generates a random sequence of integers starting from 0 like: [0,1,2,3...??]
      Parameters:
      min - minimum value of the integer that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.
      max - (optional) maximum value of the integer that will be generated. Defaults to 'min' if omitted.
      Returns:
      generated array of integers.