Class DefaultRandom

java.lang.Object
org.instancio.internal.random.DefaultRandom
All Implemented Interfaces:
Random

public class DefaultRandom extends Object implements Random
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an instance with a random seed value.
    DefaultRandom(long seed)
    Create an instance with the given seed value.
  • Method Summary

    Modifier and Type
    Method
    Description
    alphanumeric(int length)
    Generates a random alphanumeric String comprised of [a-z, A-Z, 0-9].
    char
    Returns a random alphanumeric character, [a-z, A-Z, 0-9].
    byte
    byteRange(byte min, byte max)
    Returns a random byte within the given range.
    char
    Returns a random alphabetic character, [a-z, A-Z].
    boolean
    diceRoll(boolean precondition)
    Returns true with a 1/6 probability, but only if the precondition is true.
    digits(int length)
    Generates a random String comprised of digits [0-9].
    double
    doubleRange(double min, double max)
    Returns a random double within the given range.
    float
    floatRange(float min, float max)
    Returns a random float within the given range.
    long
    Returns the seed value used by the random number generator.
    int
    intRange(int min, int max)
    Returns a random int within the given range.
    long
    longRange(long min, long max)
    Returns a random long within the given range.
    lowerCaseAlphabetic(int length)
    Generates a lower case String comprised of [a-z].
    char
    Returns a random lower alphabetic character, [a-z].
    mixedCaseAlphabetic(int length)
    Generates a random mixed case String comprised of [a-z, A-Z].
    <T> T
    oneOf(Collection<T> collection)
    Returns a random element from the given collection.
    <T> T
    oneOf(T[] array)
    Returns a random element from the given array.
    short
    shortRange(short min, short max)
    Returns a random short within the given range.
    boolean
    Returns a random boolean with a 0.5 probability.
    upperCaseAlphabetic(int length)
    Generates a random upper case String comprised of [A-Z].
    char
    Returns a random upper alphabetic character, [A-Z].

    Methods inherited from class java.lang.Object

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

    • DefaultRandom

      public DefaultRandom()
      Create an instance with a random seed value.
    • DefaultRandom

      public DefaultRandom(long seed)
      Create an instance with the given seed value.
      Parameters:
      seed - for the random generator
  • Method Details

    • getSeed

      public long getSeed()
      Description copied from interface: Random
      Returns the seed value used by the random number generator.
      Specified by:
      getSeed in interface Random
      Returns:
      seed value
    • trueOrFalse

      public boolean trueOrFalse()
      Description copied from interface: Random
      Returns a random boolean with a 0.5 probability.
      Specified by:
      trueOrFalse in interface Random
      Returns:
      a random true or false
    • diceRoll

      public boolean diceRoll(boolean precondition)
      Description copied from interface: Random
      Returns true with a 1/6 probability, but only if the precondition is true.
      Specified by:
      diceRoll in interface Random
      Parameters:
      precondition - required for returning true value
      Returns:
      a random true with 1/6 probability.
    • byteRange

      public byte byteRange(byte min, byte max)
      Description copied from interface: Random
      Returns a random byte within the given range.
      Specified by:
      byteRange in interface Random
      Parameters:
      min - lower bound
      max - upper bound (inclusive)
      Returns:
      a random byte between the min and max, inclusive
    • shortRange

      public short shortRange(short min, short max)
      Description copied from interface: Random
      Returns a random short within the given range.
      Specified by:
      shortRange in interface Random
      Parameters:
      min - lower bound
      max - upper bound (inclusive)
      Returns:
      a random short between the min and max, inclusive
    • intRange

      public int intRange(int min, int max)
      Description copied from interface: Random
      Returns a random int within the given range.
      Specified by:
      intRange in interface Random
      Parameters:
      min - lower bound
      max - upper bound (inclusive)
      Returns:
      a random int between the min and max, inclusive
    • longRange

      public long longRange(long min, long max)
      Description copied from interface: Random
      Returns a random long within the given range.
      Specified by:
      longRange in interface Random
      Parameters:
      min - lower bound
      max - upper bound (inclusive)
      Returns:
      a random long between the min and max, inclusive
    • floatRange

      public float floatRange(float min, float max)
      Description copied from interface: Random
      Returns a random float within the given range.
      Specified by:
      floatRange in interface Random
      Parameters:
      min - lower bound
      max - upper bound (inclusive)
      Returns:
      a random float between the min and max, inclusive
    • doubleRange

      public double doubleRange(double min, double max)
      Description copied from interface: Random
      Returns a random double within the given range.
      Specified by:
      doubleRange in interface Random
      Parameters:
      min - lower bound
      max - upper bound (inclusive)
      Returns:
      a random double between the min and max, inclusive
    • character

      public char character()
      Description copied from interface: Random
      Returns a random alphabetic character, [a-z, A-Z].
      Specified by:
      character in interface Random
      Returns:
      random character, either lower or upper case
    • lowerCaseCharacter

      public char lowerCaseCharacter()
      Description copied from interface: Random
      Returns a random lower alphabetic character, [a-z].
      Specified by:
      lowerCaseCharacter in interface Random
      Returns:
      random lower character
    • upperCaseCharacter

      public char upperCaseCharacter()
      Description copied from interface: Random
      Returns a random upper alphabetic character, [A-Z].
      Specified by:
      upperCaseCharacter in interface Random
      Returns:
      random uppercase character
    • alphanumericCharacter

      public char alphanumericCharacter()
      Description copied from interface: Random
      Returns a random alphanumeric character, [a-z, A-Z, 0-9].
      Specified by:
      alphanumericCharacter in interface Random
      Returns:
      an alphanumeric character
    • lowerCaseAlphabetic

      public String lowerCaseAlphabetic(int length)
      Description copied from interface: Random
      Generates a lower case String comprised of [a-z].
      Specified by:
      lowerCaseAlphabetic in interface Random
      Parameters:
      length - of a string to generate
      Returns:
      random lower case String with given length
    • upperCaseAlphabetic

      public String upperCaseAlphabetic(int length)
      Description copied from interface: Random
      Generates a random upper case String comprised of [A-Z].
      Specified by:
      upperCaseAlphabetic in interface Random
      Parameters:
      length - of a string to generate
      Returns:
      random upper case String with given length
    • digits

      public String digits(int length)
      Description copied from interface: Random
      Generates a random String comprised of digits [0-9].
      Specified by:
      digits in interface Random
      Parameters:
      length - of a string to generate
      Returns:
      random String comprised of digits with given length
    • alphanumeric

      public String alphanumeric(int length)
      Description copied from interface: Random
      Generates a random alphanumeric String comprised of [a-z, A-Z, 0-9].
      Specified by:
      alphanumeric in interface Random
      Parameters:
      length - of a string to generate
      Returns:
      random alphanumeric String with given length
    • mixedCaseAlphabetic

      public String mixedCaseAlphabetic(int length)
      Description copied from interface: Random
      Generates a random mixed case String comprised of [a-z, A-Z].
      Specified by:
      mixedCaseAlphabetic in interface Random
      Parameters:
      length - of a string to generate
      Returns:
      random mixed case String with given length
    • oneOf

      public <T> T oneOf(T[] array)
      Description copied from interface: Random
      Returns a random element from the given array.
      Specified by:
      oneOf in interface Random
      Type Parameters:
      T - element type
      Parameters:
      array - to pick a value from
      Returns:
      random element
    • oneOf

      public <T> T oneOf(Collection<T> collection)
      Description copied from interface: Random
      Returns a random element from the given collection.
      Specified by:
      oneOf in interface Random
      Type Parameters:
      T - element type
      Parameters:
      collection - to pick a value from
      Returns:
      random element