Package org.instancio.internal.random
Class RandomProviderImpl
java.lang.Object
org.instancio.internal.random.RandomProviderImpl
- All Implemented Interfaces:
RandomProvider
-
Constructor Summary
ConstructorDescriptionCreate an instance with a random seed value.RandomProviderImpl
(int seed) Create an instance with the given seed value. -
Method Summary
Modifier and TypeMethodDescriptionalphabetic
(int length) byte
byteBetween
(byte min, byte max) char
boolean
diceRoll
(boolean precondition) double
doubleBetween
(double min, double max) float
floatBetween
(float min, float max) int
getSeed()
Returns the seed value used by the random number generator.int
intBetween
(int min, int max) long
longBetween
(long min, long max) <T> T
oneOf
(Collection<T> collection) Returns a random element from given collection.<T> T
oneOf
(T[] array) Returns a random element from given array.short
shortBetween
(short min, short max) boolean
-
Constructor Details
-
RandomProviderImpl
public RandomProviderImpl()Create an instance with a random seed value. -
RandomProviderImpl
public RandomProviderImpl(int seed) Create an instance with the given seed value.- Parameters:
seed
- for the random generator
-
-
Method Details
-
getSeed
public int getSeed()Description copied from interface:RandomProvider
Returns the seed value used by the random number generator.- Specified by:
getSeed
in interfaceRandomProvider
- Returns:
- seed value
-
trueOrFalse
public boolean trueOrFalse()- Specified by:
trueOrFalse
in interfaceRandomProvider
- Returns:
- a random
true
orfalse
value with a0.5
probability.
-
diceRoll
public boolean diceRoll(boolean precondition) - Specified by:
diceRoll
in interfaceRandomProvider
- Parameters:
precondition
- required for returningtrue
value- Returns:
- a random
true
with1/6
probability.
-
byteBetween
public byte byteBetween(byte min, byte max) - Specified by:
byteBetween
in interfaceRandomProvider
- Parameters:
min
- lower boundmax
- upper bound (exclusive)- Returns:
- a random byte between the min and max, exclusive
-
shortBetween
public short shortBetween(short min, short max) - Specified by:
shortBetween
in interfaceRandomProvider
- Parameters:
min
- lower boundmax
- upper bound (exclusive)- Returns:
- a random short between the min and max, exclusive
-
intBetween
public int intBetween(int min, int max) - Specified by:
intBetween
in interfaceRandomProvider
- Parameters:
min
- lower boundmax
- upper bound (exclusive)- Returns:
- a random int between the min and max, exclusive
-
longBetween
public long longBetween(long min, long max) - Specified by:
longBetween
in interfaceRandomProvider
- Parameters:
min
- lower boundmax
- upper bound (exclusive)- Returns:
- a random long between the min and max, exclusive
-
floatBetween
public float floatBetween(float min, float max) - Specified by:
floatBetween
in interfaceRandomProvider
- Parameters:
min
- lower boundmax
- upper bound (exclusive)- Returns:
- a random float between the min and max, exclusive
-
doubleBetween
public double doubleBetween(double min, double max) - Specified by:
doubleBetween
in interfaceRandomProvider
- Parameters:
min
- lower boundmax
- upper bound (exclusive)- Returns:
- a random double between the min and max, exclusive
-
character
public char character()- Specified by:
character
in interfaceRandomProvider
- Returns:
- random uppercase character between A-Z inclusive.
-
alphabetic
- Specified by:
alphabetic
in interfaceRandomProvider
- Parameters:
length
- of the string to generate- Returns:
- random uppercase String with given length
-
oneOf
public <T> T oneOf(T[] array) Description copied from interface:RandomProvider
Returns a random element from given array.- Specified by:
oneOf
in interfaceRandomProvider
- Type Parameters:
T
- element type- Parameters:
array
- to pick a value from- Returns:
- random element
-
oneOf
Description copied from interface:RandomProvider
Returns a random element from given collection.- Specified by:
oneOf
in interfaceRandomProvider
- Type Parameters:
T
- element type- Parameters:
collection
- to pick a value from- Returns:
- random element
-