public class Arithmetic extends Object
Modifier and Type | Field and Description |
---|---|
protected static Random |
randomKernel
The underlying, shared source of randomness.
|
Modifier and Type | Method and Description |
---|---|
static int |
count(int[] values,
int target)
Counts the number of times the given value appears.
|
static void |
derandomize()
Seeds the underlying source of randomness with
0 . |
static double[] |
doubleRange(int n)
Creates a
[ range of double s. |
static double[] |
doubleRange(int m,
int n)
Creates a
[ range of double s. |
static double[] |
doubleRange(int m,
int n,
int k)
Creates a
[ range of double s with step increment k . |
static double |
entropy(double... values)
Computes the entropy.
|
static int |
gcd(int a,
int b)
Computes the greatest common divisor of the given two numbers.
|
static Random |
getRandomSource()
Retrieves the source of randomness behind the static methods of
Arithmetic . |
static int |
indexOf(int[] values,
int value)
Finds the index of the given value.
|
static long[] |
longRange(int n)
Creates a
[ range of long s. |
static long[] |
longRange(int m,
int n)
Creates a
[ range of long s. |
static long[] |
longRange(int m,
int n,
int k)
Creates a
[ range of long s with step increment k . |
static double |
max(double... values)
Computes the maximum.
|
static int |
max(int... values)
Computes the maximum.
|
static double |
min(double... values)
Computes the minimum.
|
static int |
min(int... values)
Computes the minimum.
|
static byte[] |
nextBytes(int n)
A wrapper for
Random.nextBytes(byte[]) . |
static double |
nextDouble(double a)
A wrapper for
Random.nextDouble() . |
static double |
nextGaussian(double a)
A wrapper for
Random.nextGaussian() . |
static int |
nextInt()
A wrapper for
Random.nextInt() . |
static int |
nextInt(int n)
A wrapper for
Random.nextInt(int) . |
static long |
nextLong()
A wrapper for
Random.nextLong() . |
static double |
product(double... values)
Computes the product.
|
static int |
product(int... values)
Computes the product.
|
static void |
randomize()
Seeds the underlying source of randomness with
System.nanoTime() . |
static int[] |
range(int n)
Creates a
[ range of int s. |
static int[] |
range(int m,
int n)
Creates a
[ range of int s. |
static int[] |
range(int m,
int n,
int k)
Creates a
[ range of int s with step increment k . |
static double[] |
shuffle(double[] values)
Shuffles the given array.
|
static int[] |
shuffle(int[] values)
Shuffles the given array.
|
static double |
sum(double... values)
Computes the sum.
|
static int |
sum(int... values)
Computes the sum.
|
static double |
variance(double... values)
Computes the variance.
|
protected static final Random randomKernel
public static final double max(double... values)
values
- the array.public static final double min(double... values)
values
- the array.public static final double sum(double... values)
values
- the array.public static final double product(double... values)
values
- the array.public static final double variance(double... values)
values
- the array.public static final double entropy(double... values)
values
- the array.public static final int[] shuffle(int[] values)
values
- the array.public static final double[] shuffle(double[] values)
values
- the array.public static final int product(int... values)
values
- the array.public static final int sum(int... values)
values
- the array.public static final int max(int... values)
values
- the array.public static final int min(int... values)
values
- the array.public static final int gcd(int a, int b)
a
- the first number.b
- the second number.public static final int[] range(int m, int n, int k)
[m
, n
)
range of int
s with step increment k
.m
- the (inclusive) start value.n
- the (exclusive) end value.k
- the step increment.public static final int[] range(int m, int n)
[m
, n
)
range of int
s.m
- the (inclusive) lower bound.n
- the (exclusive) upper bound.public static final int[] range(int n)
[0
, n
)
range of int
s.n
- the size of the range.public static final double[] doubleRange(int m, int n, int k)
[m
, n
)
range of double
s with step increment k
.m
- the (inclusive) start value.n
- the (exclusive) end value.k
- the step increment.public static final double[] doubleRange(int m, int n)
[m
, n
)
range of double
s.m
- the (inclusive) lower bound.n
- the (exclusive) upper bound.public static final double[] doubleRange(int n)
[0
, n
)
range of double
s.n
- the size of the range.public static final long[] longRange(int m, int n, int k)
[m
, n
)
range of long
s with step increment k
.m
- the (inclusive) start value.n
- the (exclusive) end value.k
- the step increment.public static final long[] longRange(int m, int n)
[m
, n
)
range of long
s.m
- the (inclusive) lower bound.n
- the (exclusive) upper bound.public static final long[] longRange(int n)
[0
, n
)
range of long
s.n
- the size of the range.public static final int indexOf(int[] values, int value)
values
- the array.value
- the value to search for.public static final int count(int[] values, int target)
values
- the array.target
- the value to count.public static final Random getRandomSource()
Arithmetic
.public static final int nextInt(int n)
Random.nextInt(int)
.n
- the upper bound.int
in [0
, n
)
.public static final int nextInt()
Random.nextInt()
.int
chosen uniformly at random.public static final long nextLong()
Random.nextLong()
.long
chosen uniformly at random.public static final double nextDouble(double a)
Random.nextDouble()
.a
- the upper bound.double
in [0
, a
)
.public static final double nextGaussian(double a)
Random.nextGaussian()
.a
- the standard deviation.0
and standard deviation a
.public static final byte[] nextBytes(int n)
Random.nextBytes(byte[])
.n
- the size of the random byte
array.byte
array of length n
.public static final void randomize()
System.nanoTime()
.public static final void derandomize()
0
.