Package jodd.util
Class MathUtil
- java.lang.Object
-
- jodd.util.MathUtil
-
public class MathUtil extends java.lang.Object
Various math utilities. note: Any random values from this class are not cryptographically secure!
-
-
Constructor Summary
Constructors Constructor Description MathUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
humanReadableByteCount(long bytes, boolean useSi)
Formats byte size to human readable bytecount.static boolean
isEven(int x)
Returnstrue
if a number is even.static boolean
isOdd(int x)
Returnstrue
if a number is odd.static int
parseDigit(char digit)
Converts char digit into integer value.static int
randomInt(int min, int max)
Generates pseudo-random integer from specific range.static long
randomLong(long min, long max)
Generates pseudo-random long from specific range.
-
-
-
Method Detail
-
parseDigit
public static int parseDigit(char digit)
Converts char digit into integer value. Accepts numeric chars (0 - 9) as well as letter (A-z).
-
randomLong
public static long randomLong(long min, long max)
Generates pseudo-random long from specific range. Generated number is great or equals to min parameter value and less then max parameter value.- Parameters:
min
- lower (inclusive) boundarymax
- higher (exclusive) boundary- Returns:
- pseudo-random value
-
randomInt
public static int randomInt(int min, int max)
Generates pseudo-random integer from specific range. Generated number is great or equals to min parameter value and less then max parameter value.- Parameters:
min
- lower (inclusive) boundarymax
- higher (exclusive) boundary- Returns:
- pseudo-random value
-
isEven
public static boolean isEven(int x)
Returnstrue
if a number is even.
-
isOdd
public static boolean isOdd(int x)
Returnstrue
if a number is odd.
-
humanReadableByteCount
public static java.lang.String humanReadableByteCount(long bytes, boolean useSi)
Formats byte size to human readable bytecount. https://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java/3758880#3758880
-
-