Package org.pipservices3.commons.random
Class RandomInteger
java.lang.Object
org.pipservices3.commons.random.RandomInteger
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic 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'].sequence
(int size) Generates a random sequence of integers starting from 0 like: [0,1,2,3...??]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 definedstatic int
updateInteger
(int value, int range) Updates (drifts) a integer value within specified range defined
-
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
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
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.
-