Class MathUtil

java.lang.Object
jodd.util.MathUtil

public class MathUtil extends Object
Various math utilities. note: Any random values from this class are not cryptographically secure!
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    humanReadableByteCount(long bytes, boolean useSi)
    Formats byte size to human readable bytecount.
    static boolean
    isEven(int x)
    Returns true if a number is even.
    static boolean
    isOdd(int x)
    Returns true 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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MathUtil

      public MathUtil()
  • Method Details

    • 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) boundary
      max - 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) boundary
      max - higher (exclusive) boundary
      Returns:
      pseudo-random value
    • isEven

      public static boolean isEven(int x)
      Returns true if a number is even.
    • isOdd

      public static boolean isOdd(int x)
      Returns true if a number is odd.
    • humanReadableByteCount

      public static 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