Package org.pipservices3.commons.random
Class RandomLong
java.lang.Object
org.pipservices3.commons.random.RandomLong
Random generator for long values.
### Example ###
long value1 = RandomLong.nextLong(5, 10); // Possible result: 7
long value2 = RandomLong.nextLong(10); // Possible result: 3
long value3 = RandomLong.nextLong(10, 3); // Possible result: 9
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic long
nextLong
(long maxValue) Generates a long in the range [0, 'max'].static long
nextLong
(long minValue, long maxValue) Generates a long in the range ['min', 'max'].sequence
(long size) Generates a random sequence of longs starting from 0 like: [0,1,2,3...??]sequence
(long min, long max) Generates a random sequence of longs starting from 0 like: [0,1,2,3...??]static long
updateLong
(long value) Updates (drifts) a long value without specified range definedstatic long
updateLong
(long value, long range) Updates (drifts) a long value within specified range defined
-
Constructor Details
-
RandomLong
public RandomLong()
-
-
Method Details
-
nextLong
public static long nextLong(long maxValue) Generates a long in the range [0, 'max'].- Parameters:
maxValue
- (optional) maximum value of the long that will be generated. Defaults to 'min' if omitted.- Returns:
- generated random long value.
-
nextLong
public static long nextLong(long minValue, long maxValue) Generates a long in the range ['min', 'max']. If 'max' is omitted, then the range will be set to [0, 'min'].- Parameters:
minValue
- minimum value of the long that will be generated. If 'max' is omitted, then 'max' is set to 'min' and 'min' is set to 0.maxValue
- (optional) maximum value of the long that will be generated. Defaults to 'min' if omitted.- Returns:
- generated random long value.
-
updateLong
public static long updateLong(long value) Updates (drifts) a long value without specified range defined- Parameters:
value
- a long value to drift.- Returns:
- updated random long value.
-
updateLong
public static long updateLong(long value, long range) Updates (drifts) a long value within specified range defined- Parameters:
value
- a long value to drift.range
- (optional) a range. Default: 10% of the value- Returns:
- updated random long value.
-
sequence
Generates a random sequence of longs starting from 0 like: [0,1,2,3...??]- Parameters:
size
- size of sequence.- Returns:
- generated array of longs.
-
sequence
Generates a random sequence of longs starting from 0 like: [0,1,2,3...??]- Parameters:
min
- minimum value of the long 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 long that will be generated. Defaults to 'min' if omitted.- Returns:
- generated array of longs.
-