public class MathUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static short |
convertIntToShort(int i)
Convert an int value to a short value.
|
static int |
convertLongToInt(long l)
Convert a long value to an int value.
|
static byte[] |
generateAlternativeSeed()
Generate a seed value, using as much unpredictable data as possible.
|
static int |
nextPowerOf2(int x)
Get the value that is equal to or higher than this value, and that is a
power of two.
|
static void |
randomBytes(byte[] bytes)
Get a number of pseudo random bytes.
|
static int |
randomInt(int lowerThan)
Get a pseudo random int value between 0 (including and the given value
(excluding).
|
static int |
roundUpInt(int x,
int blockSizePowerOf2)
Round the value up to the next block size.
|
static long |
roundUpLong(long x,
long blockSizePowerOf2)
Round the value up to the next block size.
|
static byte[] |
secureRandomBytes(int len)
Get a number of cryptographically secure pseudo random bytes.
|
static int |
secureRandomInt(int lowerThan)
Get a cryptographically secure pseudo random int value between 0
(including and the given value (excluding).
|
static long |
secureRandomLong()
Get a cryptographically secure pseudo random long value.
|
public static int roundUpInt(int x, int blockSizePowerOf2)
x
- the value to be roundedblockSizePowerOf2
- the block sizepublic static long roundUpLong(long x, long blockSizePowerOf2)
x
- the value to be roundedblockSizePowerOf2
- the block sizepublic static byte[] generateAlternativeSeed()
public static int nextPowerOf2(int x) throws java.lang.IllegalArgumentException
x
- the original valuejava.lang.IllegalArgumentException
- if x < 0 or x > 0x40000000public static int convertLongToInt(long l)
l
- the value to convertpublic static short convertIntToShort(int i)
i
- the value to convertpublic static long secureRandomLong()
public static void randomBytes(byte[] bytes)
bytes
- the target arraypublic static byte[] secureRandomBytes(int len)
len
- the number of bytespublic static int randomInt(int lowerThan)
lowerThan
- the value returned will be lower than this valuepublic static int secureRandomInt(int lowerThan)
lowerThan
- the value returned will be lower than this value