Package org.instancio.internal.random
Class DefaultRandom
- java.lang.Object
-
- org.instancio.internal.random.DefaultRandom
-
-
Constructor Summary
Constructors Constructor Description DefaultRandom()
Create an instance with a random seed value.DefaultRandom(int seed)
Create an instance with the given seed value.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
alphanumeric(int length)
Generates a random alphanumeric String comprised of[a-z, A-Z, 0-9]
.char
alphanumericCharacter()
Returns a random alphanumeric character,[a-z, A-Z, 0-9]
.byte
byteRange(byte min, byte max)
Returns a randombyte
within the given range.char
character()
Returns a random alphabetic character,[a-z, A-Z]
.boolean
diceRoll(boolean precondition)
Returnstrue
with a1/6
probability, but only if theprecondition
is true.String
digits(int length)
Generates a random String comprised of digits[0-9]
.double
doubleRange(double min, double max)
Returns a randomdouble
within the given range.float
floatRange(float min, float max)
Returns a randomfloat
within the given range.int
getSeed()
Returns the seed value used by the random number generator.int
intRange(int min, int max)
Returns a randomint
within the given range.long
longRange(long min, long max)
Returns a randomlong
within the given range.String
lowerCaseAlphabetic(int length)
Generates a lower case String comprised of[a-z]
.char
lowerCaseCharacter()
Returns a random lower alphabetic character,[a-z]
.String
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 randomshort
within the given range.boolean
trueOrFalse()
Returns a random boolean with a0.5
probability.String
upperCaseAlphabetic(int length)
Generates a random upper case String comprised of[A-Z]
.char
upperCaseCharacter()
Returns a random upper alphabetic character,[A-Z]
.
-
-
-
Method Detail
-
getSeed
public int getSeed()
Description copied from interface:Random
Returns the seed value used by the random number generator.
-
trueOrFalse
public boolean trueOrFalse()
Description copied from interface:Random
Returns a random boolean with a0.5
probability.- Specified by:
trueOrFalse
in interfaceRandom
- Returns:
- a random
true
orfalse
-
diceRoll
public boolean diceRoll(boolean precondition)
Description copied from interface:Random
Returnstrue
with a1/6
probability, but only if theprecondition
is true.
-
byteRange
public byte byteRange(byte min, byte max)
Description copied from interface:Random
Returns a randombyte
within the given range.
-
shortRange
public short shortRange(short min, short max)
Description copied from interface:Random
Returns a randomshort
within the given range.- Specified by:
shortRange
in interfaceRandom
- Parameters:
min
- lower boundmax
- 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 randomint
within the given range.
-
longRange
public long longRange(long min, long max)
Description copied from interface:Random
Returns a randomlong
within the given range.
-
floatRange
public float floatRange(float min, float max)
Description copied from interface:Random
Returns a randomfloat
within the given range.- Specified by:
floatRange
in interfaceRandom
- Parameters:
min
- lower boundmax
- 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 randomdouble
within the given range.- Specified by:
doubleRange
in interfaceRandom
- Parameters:
min
- lower boundmax
- 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]
.
-
lowerCaseCharacter
public char lowerCaseCharacter()
Description copied from interface:Random
Returns a random lower alphabetic character,[a-z]
.- Specified by:
lowerCaseCharacter
in interfaceRandom
- 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 interfaceRandom
- 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 interfaceRandom
- 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 interfaceRandom
- 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 interfaceRandom
- 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]
.
-
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 interfaceRandom
- 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 interfaceRandom
- 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.
-
oneOf
public <T> T oneOf(Collection<T> collection)
Description copied from interface:Random
Returns a random element from the given collection.
-
-