Class Randomizer

java.lang.Object
com.marcpg.libpg.util.Randomizer

public final class Randomizer extends Object
Used to get random values from things
Since:
0.0.1
  • Field Details

    • BASIC_CHARS

      public static final String BASIC_CHARS
      All basic characters that are on a keyboard and supported in most fonts and formats.
      See Also:
  • Method Details

    • boolByChance

      public static boolean boolByChance(int numerator, int denominator)
      Returns a random boolean value based on a fraction represented by the numerator and denominator. The numerator represents the desired outcomes, while the denominator represents the total possibilities.
      Parameters:
      numerator - The number of desired outcomes.
      denominator - The total number of possibilities.
      Returns:
      Returns true or false randomly based on the fraction represented by the numerator and denominator.
    • boolByChance

      public static boolean boolByChance(double percentage)
      Returns a random boolean value based on a percentage. A 1% chance would almost always return false. A 99% chance would almost always return true.
      Parameters:
      percentage - The chance in percentage (0-100%) to return true.
      Returns:
      Returns true or false randomly based on the input percentage.
    • fromCollection

      public static <T> T fromCollection(Collection<T> in)
      Returns a random object from the given collection.
      Type Parameters:
      T - The type of elements in the list.
      Parameters:
      in - The collection from which a random object should be selected.
      Returns:
      A random thing from the input collection.
    • fromArray

      public static <T> T fromArray(T @NotNull [] in)
      Returns a random object from the given array.
      Type Parameters:
      T - The type of elements in the array.
      Parameters:
      in - The array from which a random object should be selected.
      Returns:
      A random object from the input array.
    • generateRandomString

      @NotNull public static @NotNull String generateRandomString(Integer length, String charset)
      Generates a random string based on available characters and a length.
      Parameters:
      length - The length of the string.
      charset - What characters can be used in the string.
      Returns:
      A randomly generated string.
    • generateRandomString

      @NotNull public static @NotNull String generateRandomString(int length)
      Generates a random string based on basic characters and a length.
      Parameters:
      length - The length of the randomly generated string.
      Returns:
      A randomly generated string.
    • generateRandomPassword

      @NotNull public static @NotNull String generateRandomPassword(Integer length, String charset)
      Generates a random password based on available characters and a length. What makes this different from generateRandomString(int) is the usage of SecureRandom.
      Parameters:
      length - The length of the password.
      charset - What characters can be used in the password.
      Returns:
      A randomly generated password.
    • generateRandomPassword

      @NotNull public static @NotNull String generateRandomPassword(int length)
      Generates a random password based on basic characters and a length. What makes this different from generateRandomString(int) is the usage of SecureRandom.
      Parameters:
      length - The length of the password.
      Returns:
      A randomly generated password.
    • randomChar

      public static char randomChar(@NotNull @NotNull String charset)
      Picks a random character out of a string.
      Parameters:
      charset - All available characters, can have one character multiple times.
      Returns:
      A random character.
    • randomChar

      public static char randomChar()
      Picks a random character out of basic characters.
      Returns:
      A random character.
    • newRandom

      public static void newRandom()
      Resets the random to get true randomness.