Class RandomUtils

java.lang.Object
de.presti.ree6.utils.others.RandomUtils

public final class RandomUtils extends Object
Utility class for random things.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Random
    An instance of the used Random.
    static final SecureRandom
    An instance of the used SecureRandom.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Create a new Base64 String.
    static double
    nextDouble(double startInclusive, double endInclusive)
    Generates a random number between the given min and the given max.
    static float
    nextFloat(float startInclusive, float endInclusive)
    Generates a random number between the given min and the given max.
    static int
    nextInt(int startInclusive, int endExclusive)
    Generates a random number between the given min and the given max.
    static String
    random(int length, char[] chars)
    Generates a string with the given length and amount of characters.
    static String
    random(int length, String chars)
    Generates a string with the given length and amount of characters.
    static String
    randomNumber(int length)
    Generates a random number with the given amount of digits.
    static String
    randomString(int length, boolean specialChars)
    Generates a string with the given amount of characters.
    static double
    round(double value, int places)
    Round a double.

    Methods inherited from class java.lang.Object

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

    • random

      public static final Random random
      An instance of the used Random.
    • secureRandom

      public static final SecureRandom secureRandom
      An instance of the used SecureRandom.
  • Method Details

    • nextInt

      public static int nextInt(int startInclusive, int endExclusive)
      Generates a random number between the given min and the given max.
      Parameters:
      startInclusive - The minimum number.
      endExclusive - The maximum number.
      Returns:
      A random number between the given min and the given max.
    • nextDouble

      public static double nextDouble(double startInclusive, double endInclusive)
      Generates a random number between the given min and the given max.
      Parameters:
      startInclusive - The minimum number.
      endInclusive - The maximum number.
      Returns:
      A random number between the given min and the given max.
    • nextFloat

      public static float nextFloat(float startInclusive, float endInclusive)
      Generates a random number between the given min and the given max.
      Parameters:
      startInclusive - The minimum number.
      endInclusive - The maximum number.
      Returns:
      A random number between the given min and the given max.
    • randomNumber

      public static String randomNumber(int length)
      Generates a random number with the given amount of digits.
      Parameters:
      length - The amount of digits.
      Returns:
      A random number with the given amount of digits.
    • randomString

      public static String randomString(int length, boolean specialChars)
      Generates a string with the given amount of characters.
      Parameters:
      length - The amount of characters.
      specialChars - If special characters should be used.
      Returns:
      A string with the given amount of characters.
    • random

      public static String random(int length, String chars)
      Generates a string with the given length and amount of characters.
      Parameters:
      length - The amount of characters.
      chars - The characters to use.
      Returns:
      A string with the given amount of characters.
    • random

      public static String random(int length, char[] chars)
      Generates a string with the given length and amount of characters.
      Parameters:
      length - The amount of characters.
      chars - The characters to use.
      Returns:
      A string with the given amount of characters.
    • getRandomBase64String

      public static String getRandomBase64String(int length)
      Create a new Base64 String.
      Parameters:
      length - The length of the String.
      Returns:
      String A Base64 String.
    • round

      public static double round(double value, int places)
      Round a double.
      Parameters:
      value - the double to round.
      places - the fixed decimal points.
      Returns:
      the round double.