Package org.instancio.support
Class DefaultRandom
java.lang.Object
org.instancio.support.DefaultRandom
- All Implemented Interfaces:
Random
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance with a random seed value.DefaultRandom(long seed) Create an instance with the given seed value. -
Method Summary
Modifier and TypeMethodDescriptionalphanumeric(int length) Generates a random alphanumeric String comprised of[a-z, A-Z, 0-9].charReturns a random alphanumeric character,[a-z, A-Z, 0-9].bytebyteRange(byte min, byte max) Returns a randombytewithin the given range.charReturns a random alphabetic character,[a-z, A-Z].charcharacterRange(char min, char max) Returns a randomcharwithin the given range.booleandiceRoll(boolean precondition) Returnstruewith a1/6probability, but only if thepreconditionis true.digits(int length) Generates a random String comprised of digits[0-9].doubledoubleRange(double min, double max) Returns a randomdoublewithin the given range.floatfloatRange(float min, float max) Returns a randomfloatwithin the given range.longgetSeed()Returns the seed value used by the random number generator.intintRange(int min, int max) Returns a randomintwithin the given range.longlongRange(long min, long max) Returns a randomlongwithin the given range.lowerCaseAlphabetic(int length) Generates a lower case String comprised of[a-z].charReturns a random lower alphabetic character,[a-z].mixedCaseAlphabetic(int length) Generates a random mixed case String comprised of[a-z, A-Z].<T> ToneOf(Collection<T> collection) Returns a random element from the given collection.<T> ToneOf(T[] array) Returns a random element from the given array.shortshortRange(short min, short max) Returns a randomshortwithin the given range.stringOf(int length, char... chars) Generates a random String of the specified length comprised of given characters.booleanReturns a random boolean with a0.5probability.booleantrueOrFalse(double probability) Returnstruewith the specified probability.upperCaseAlphabetic(int length) Generates a random upper case String comprised of[A-Z].charReturns a random upper alphabetic character,[A-Z].
-
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:RandomReturns the seed value used by the random number generator. -
trueOrFalse
public boolean trueOrFalse()Description copied from interface:RandomReturns a random boolean with a0.5probability.- Specified by:
trueOrFalsein interfaceRandom- Returns:
- a random
trueorfalse
-
trueOrFalse
public boolean trueOrFalse(double probability) Description copied from interface:RandomReturnstruewith the specified probability.- Specified by:
trueOrFalsein interfaceRandom- Parameters:
probability- of returningtrue- Returns:
- a random
trueorfalse
-
diceRoll
public boolean diceRoll(boolean precondition) Description copied from interface:RandomReturnstruewith a1/6probability, but only if thepreconditionis true. -
byteRange
public byte byteRange(byte min, byte max) Description copied from interface:RandomReturns a randombytewithin the given range. -
shortRange
public short shortRange(short min, short max) Description copied from interface:RandomReturns a randomshortwithin the given range.- Specified by:
shortRangein interfaceRandom- Parameters:
min- lower bound (inclusive)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:RandomReturns a randomintwithin the given range. -
longRange
public long longRange(long min, long max) Description copied from interface:RandomReturns a randomlongwithin the given range. -
floatRange
public float floatRange(float min, float max) Description copied from interface:RandomReturns a randomfloatwithin the given range.- Specified by:
floatRangein interfaceRandom- Parameters:
min- lower bound (inclusive)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:RandomReturns a randomdoublewithin the given range.- Specified by:
doubleRangein interfaceRandom- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random double between the min and max, inclusive
-
characterRange
public char characterRange(char min, char max) Description copied from interface:RandomReturns a randomcharwithin the given range.- Specified by:
characterRangein interfaceRandom- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random character between the min and max, inclusive
-
character
public char character()Description copied from interface:RandomReturns a random alphabetic character,[a-z, A-Z]. -
lowerCaseCharacter
public char lowerCaseCharacter()Description copied from interface:RandomReturns a random lower alphabetic character,[a-z].- Specified by:
lowerCaseCharacterin interfaceRandom- Returns:
- random lower character
-
upperCaseCharacter
public char upperCaseCharacter()Description copied from interface:RandomReturns a random upper alphabetic character,[A-Z].- Specified by:
upperCaseCharacterin interfaceRandom- Returns:
- random uppercase character
-
alphanumericCharacter
public char alphanumericCharacter()Description copied from interface:RandomReturns a random alphanumeric character,[a-z, A-Z, 0-9].- Specified by:
alphanumericCharacterin interfaceRandom- Returns:
- an alphanumeric character
-
lowerCaseAlphabetic
Description copied from interface:RandomGenerates a lower case String comprised of[a-z].- Specified by:
lowerCaseAlphabeticin interfaceRandom- Parameters:
length- of a string to generate- Returns:
- random lower case String with given length
-
upperCaseAlphabetic
Description copied from interface:RandomGenerates a random upper case String comprised of[A-Z].- Specified by:
upperCaseAlphabeticin interfaceRandom- Parameters:
length- of a string to generate- Returns:
- random upper case String with given length
-
digits
Description copied from interface:RandomGenerates a random String comprised of digits[0-9]. -
stringOf
Description copied from interface:RandomGenerates a random String of the specified length comprised of given characters. -
alphanumeric
Description copied from interface:RandomGenerates a random alphanumeric String comprised of[a-z, A-Z, 0-9].- Specified by:
alphanumericin interfaceRandom- Parameters:
length- of a string to generate- Returns:
- random alphanumeric String with given length
-
mixedCaseAlphabetic
Description copied from interface:RandomGenerates a random mixed case String comprised of[a-z, A-Z].- Specified by:
mixedCaseAlphabeticin 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:RandomReturns a random element from the given array. -
oneOf
Description copied from interface:RandomReturns a random element from the given collection.
-