public class RandomUtils extends Object
Provides static methods to obtain both random numbers and vectors.
Modifier and Type | Method and Description |
---|---|
static double |
random(double minValue,
double maxValue)
Returns a random double in range [minValue, maxValue]
|
static double[] |
random(double minValue,
double maxValue,
int size)
Returns a random double vector, with elements in range [minValue, maxValue]
|
static double[] |
random(double minValue,
double maxValue,
int size,
Random r)
Returns a random double vector, with elements in range [minValue, maxValue]
|
static double |
random(double minValue,
double maxValue,
Random r)
Returns a random double in range [minValue, maxValue]
|
static int |
random(int minValue,
int maxValue)
Returns a random integer in range [minValue, maxValue]
|
static int[] |
random(int minValue,
int maxValue,
int size)
Returns a random integer vector, with elements in range [minValue, maxValue]
|
static int[] |
random(int minValue,
int maxValue,
int size,
Random r)
Returns a random integer vector, with elements in range [minValue, maxValue]
|
static int |
random(int minValue,
int maxValue,
Random r)
Returns a random integer in range [minValue, maxValue]
|
static long |
random(long minValue,
long maxValue)
Returns a random long in range [minValue, maxValue]
|
static long[] |
random(long minValue,
long maxValue,
int size)
Returns a random long vector, with elements in range [minValue, maxValue]
|
static long[] |
random(long minValue,
long maxValue,
int size,
Random r)
Returns a random long vector, with elements in range [minValue, maxValue]
|
static long |
random(long minValue,
long maxValue,
Random r)
Returns a random long in range [minValue, maxValue]
|
static int |
select(double[] array)
Returns the index of a random item of an array with uniform probability.
|
static int |
select(double[] array,
Random r)
Returns the index of a random item of an array with uniform probability.
|
static int |
select(int[] array)
Returns the index of a random item of an array with uniform probability.
|
static int |
select(int[] array,
Random r)
Returns the index of a random item of an array with uniform probability.
|
static int |
select(long[] array)
Returns the index of a random item of an array with uniform probability.
|
static int |
select(long[] array,
Random r)
Returns the index of a random item of an array with uniform probability.
|
static int |
selectWeighted(double[] weightArray)
Returns the index of a random item of an array where the chances of choosing
it are relative to its weight.
|
static int |
selectWeighted(double[] weightArray,
Random r)
Returns the index of a random item of an array where the chances of choosing
it are relative to its weight.
|
static void |
shuffle(double[] array)
Implements Fisher-Yates shuffle.
|
static void |
shuffle(double[] array,
Random r)
Implements Fisher-Yates shuffle.
|
static void |
shuffle(int[] array)
Implements Fisher-Yates shuffle.
|
static void |
shuffle(int[] array,
Random r)
Implements Fisher-Yates shuffle.
|
static void |
shuffle(long[] array)
Implements Fisher-Yates shuffle.
|
static void |
shuffle(long[] array,
Random r)
Implements Fisher-Yates shuffle.
|
public static double random(double minValue, double maxValue)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)public static double[] random(double minValue, double maxValue, int size)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)size
- Number of elementspublic static double[] random(double minValue, double maxValue, int size, Random r)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)size
- Number of elementsr
- Random generatorpublic static double random(double minValue, double maxValue, Random r)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)r
- Random generatorpublic static int random(int minValue, int maxValue)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)public static int[] random(int minValue, int maxValue, int size)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)size
- Number of elementspublic static int[] random(int minValue, int maxValue, int size, Random r)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)size
- Number of elementsr
- Random generatorpublic static int random(int minValue, int maxValue, Random r)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)r
- Random generatorpublic static long random(long minValue, long maxValue)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)public static long[] random(long minValue, long maxValue, int size)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)size
- Number of elementspublic static long[] random(long minValue, long maxValue, int size, Random r)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)size
- Number of elementsr
- Random generatorpublic static long random(long minValue, long maxValue, Random r)
minValue
- Minimum value (inclusive)maxValue
- Maximum value (inclusive)r
- Random generatorpublic static int select(double[] array)
array
- Input arraypublic static int select(double[] array, Random r)
array
- Input arrayr
- Random generatorpublic static int select(int[] array)
array
- Input arraypublic static int select(int[] array, Random r)
array
- Input arrayr
- Random generatorpublic static int select(long[] array)
array
- Input arraypublic static int select(long[] array, Random r)
array
- Input arrayr
- Random generatorpublic static int selectWeighted(double[] weightArray)
weightArray
- Weight arraypublic static int selectWeighted(double[] weightArray, Random r)
weightArray
- Weight arrayr
- Random generatorpublic static void shuffle(double[] array)
array
- Array to be shuffledpublic static void shuffle(double[] array, Random r)
array
- Array to be shuffledr
- Random generatorpublic static void shuffle(int[] array)
array
- Array to be shuffledpublic static void shuffle(int[] array, Random r)
array
- Array to be shuffledr
- Random generatorpublic static void shuffle(long[] array)
array
- Array to be shuffledpublic static void shuffle(long[] array, Random r)
array
- Array to be shuffledr
- Random generatorCopyright © 2018. All rights reserved.