Package org.instancio
Interface Random
public interface Random
Provides methods for generating random values such as numbers,
booleans, characters, and strings.
- Since:
- 1.2.1
-
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].
-
Method Details
-
getSeed
long getSeed()Returns the seed value used by the random number generator.- Returns:
- seed value
-
trueOrFalse
boolean trueOrFalse()Returns a random boolean with a0.5probability.- Returns:
- a random
trueorfalse
-
trueOrFalse
boolean trueOrFalse(double probability) Returnstruewith the specified probability.- Parameters:
probability- of returningtrue- Returns:
- a random
trueorfalse - Since:
- 2.11.0
-
diceRoll
boolean diceRoll(boolean precondition) Returnstruewith a1/6probability, but only if thepreconditionis true.- Parameters:
precondition- required for returningtruevalue- Returns:
- a random
truewith1/6probability.
-
byteRange
byte byteRange(byte min, byte max) Returns a randombytewithin the given range.- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random byte between the min and max, inclusive
-
shortRange
short shortRange(short min, short max) Returns a randomshortwithin the given range.- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random short between the min and max, inclusive
-
intRange
int intRange(int min, int max) Returns a randomintwithin the given range.- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random int between the min and max, inclusive
-
longRange
long longRange(long min, long max) Returns a randomlongwithin the given range.- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random long between the min and max, inclusive
-
floatRange
float floatRange(float min, float max) Returns a randomfloatwithin the given range.- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random float between the min and max, inclusive
-
doubleRange
double doubleRange(double min, double max) Returns a randomdoublewithin the given range.- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random double between the min and max, inclusive
-
characterRange
char characterRange(char min, char max) Returns a randomcharwithin the given range.- Parameters:
min- lower bound (inclusive)max- upper bound (inclusive)- Returns:
- a random character between the min and max, inclusive
- Since:
- 2.8.0
-
character
char character()Returns a random alphabetic character,[a-z, A-Z].- Returns:
- random character, either lower or upper case
-
alphanumericCharacter
char alphanumericCharacter()Returns a random alphanumeric character,[a-z, A-Z, 0-9].- Returns:
- an alphanumeric character
-
lowerCaseCharacter
char lowerCaseCharacter()Returns a random lower alphabetic character,[a-z].- Returns:
- random lower character
-
upperCaseCharacter
char upperCaseCharacter()Returns a random upper alphabetic character,[A-Z].- Returns:
- random uppercase character
-
lowerCaseAlphabetic
Generates a lower case String comprised of[a-z].- Parameters:
length- of a string to generate- Returns:
- random lower case String with given length
-
upperCaseAlphabetic
Generates a random upper case String comprised of[A-Z].- Parameters:
length- of a string to generate- Returns:
- random upper case String with given length
-
mixedCaseAlphabetic
Generates a random mixed case String comprised of[a-z, A-Z].- Parameters:
length- of a string to generate- Returns:
- random mixed case String with given length
-
alphanumeric
Generates a random alphanumeric String comprised of[a-z, A-Z, 0-9].- Parameters:
length- of a string to generate- Returns:
- random alphanumeric String with given length
-
digits
Generates a random String comprised of digits[0-9].- Parameters:
length- of a string to generate- Returns:
- random String comprised of digits with given length
-
stringOf
Generates a random String of the specified length comprised of given characters.- Parameters:
length- of a string to generatechars- characters to generate the string from- Returns:
- random String containing chars from the input array
-
oneOf
<T> T oneOf(T... array) Returns a random element from the given array.- Type Parameters:
T- element type- Parameters:
array- to pick a value from- Returns:
- random element
-
oneOf
Returns a random element from the given collection.- Type Parameters:
T- element type- Parameters:
collection- to pick a value from- Returns:
- random element
-