class RandomService: IRandom, Any
Fields
Name | Description |
---|---|
val config: FakerConfig
|
Methods
nextInt
fun nextInt(): Int
Returns the next pseudorandom, uniformly distributed Int value from this random number generator's sequence.
ReturnValue
Name | Description |
---|---|
Int
|
nextInt
fun nextInt(bound: Int): Int
Returns a pseudorandom, uniformly distributed Int value between 0
(inclusive)
and the specified bound (exclusive),
drawn from this random number generator's sequence.
Parameters
Name | Description |
---|---|
bound: Int
|
ReturnValue
Name | Description |
---|---|
Int
|
nextInt
fun nextInt(intRange: IntRange): Int
Returns a pseudorandom, uniformly distributed Int value within the specified int range (inclusive), drawn from this random number generator's sequence.
Parameters
Name | Description |
---|---|
intRange: IntRange
|
ReturnValue
Name | Description |
---|---|
Int
|
nextInt
fun nextInt(min: Int, max: Int): Int
Returns a pseudorandom, uniformly distributed Int value between min (inclusive) and max (inclusive), drawn from this random number generator's sequence.
Parameters
Name | Description |
---|---|
min: Int
|
|
max: Int
|
ReturnValue
Name | Description |
---|---|
Int
|
randomValue
fun <T> randomValue(list: List<T>): T
Returns a pseudo-randomly selected value from the list of values.
Parameters
Name | Description |
---|---|
list: List<T>
|
ReturnValue
Name | Description |
---|---|
T
|
randomValue
fun <T> randomValue(array: Array<T>): T
Returns a pseudo-randomly selected value from the array of values.
Parameters
Name | Description |
---|---|
array: Array<T>
|
ReturnValue
Name | Description |
---|---|
T
|
nextLetter
fun nextLetter(upper: Boolean): Char
Returns the next pseudorandom, uniformly distributed Char value that corresponds to a letter in the English alphabet.
Parameters
Name | Description |
---|---|
upper: Boolean
|
returns the Char in upper-case if set to |
ReturnValue
Name | Description |
---|---|
Char
|
randomString
fun randomString(length: Int, numericalChars: Boolean): String
Returns String with the specified length consisting of a pseudo-randomly generated
English alphabet letters and optional numericalChars,
or an empty string for a length < 1
.
Parameters
Name | Description |
---|---|
length: Int
|
the length of the resulting string.
Default: |
numericalChars: Boolean
|
add additional numerical chars from 0 to 9 to the resulting string.
Default: |
ReturnValue
Name | Description |
---|---|
String
|
randomString
fun randomString(length: Int, locale: Locale, indexChars: Boolean, auxiliaryChars: Boolean, punctuationChars: Boolean, numericalChars: Boolean): String
Returns String with the specified length (or an empty string for a length < 1
)
consisting of pseudo-randomly generated characters
in a given locale with optional auxiliaryChars and numericalChars
Parameters
Name | Description |
---|---|
length: Int
|
the length of the resulting string.
Default: |
locale: Locale
|
locale to use to generate the charset.
Defaults to |
indexChars: Boolean
|
add additional index chars to the resulting string, as defined in
Character_Elements.
Default: |
auxiliaryChars: Boolean
|
add additional auxiliary chars to the resulting string as defined in
Character_Elements.
Default: |
punctuationChars: Boolean
|
|
numericalChars: Boolean
|
add additional numerical chars from 0 to 9 to the resulting string
Default: |
ReturnValue
Name | Description |
---|---|
String
|
randomString
fun randomString(min: Int, max: Int, locale: Locale, indexChars: Boolean, auxiliaryChars: Boolean, punctuationChars: Boolean, numericalChars: Boolean): String
Returns String with a randomLength withing the specified min and max boundaries
(or an empty string for if randomLength < 1
)
consisting of pseudo-randomly generated characters
in a given locale with optional auxiliaryChars and numericalChars
Parameters
Name | Description |
---|---|
min: Int
|
the minimum length of the resulting string. |
max: Int
|
the maximum length of the resulting string. |
locale: Locale
|
locale to use to generate the charset.
Defaults to |
indexChars: Boolean
|
add additional index chars to the resulting string, as defined in
Character_Elements.
Default: |
auxiliaryChars: Boolean
|
add additional auxiliary chars to the resulting string as defined in
Character_Elements.
Default: |
punctuationChars: Boolean
|
|
numericalChars: Boolean
|
add additional numerical chars from 0 to 9 to the resulting string
Default: |
ReturnValue
Name | Description |
---|---|
String
|
nextBoolean
fun nextBoolean(): Boolean
Returns the next pseudorandom, uniformly distributed Boolean value from this random number generator's sequence.
The values true
and false
are produced with (approximately) equal probability.
ReturnValue
Name | Description |
---|---|
Boolean
|
nextLong
fun nextLong(): Long
Returns the next pseudorandom, uniformly distributed Long value from this random number generator's sequence.
ReturnValue
Name | Description |
---|---|
Long
|
nextLong
fun nextLong(bound: Long): Long
Returns a pseudorandom, uniformly distributed Long value between 0
(inclusive),
and the specified bound value (exclusive),
drawn from this random number generator's sequence.
Parameters
Name | Description |
---|---|
bound: Long
|
ReturnValue
Name | Description |
---|---|
Long
|
nextLong
fun nextLong(longRange: LongRange): Long
Returns a pseudorandom, uniformly distributed Long value within the specified longRange (inclusive), drawn from this random number generator's sequence.
Parameters
Name | Description |
---|---|
longRange: LongRange
|
ReturnValue
Name | Description |
---|---|
Long
|
nextLong
fun nextLong(min: Long, max: Long): Long
Returns a pseudorandom, uniformly distributed Long value between min (inclusive) and max (inclusive), drawn from this random number generator's sequence.
Parameters
Name | Description |
---|---|
min: Long
|
|
max: Long
|
ReturnValue
Name | Description |
---|---|
Long
|
nextFloat
fun nextFloat(): Float
Returns the next pseudorandom, uniformly distributed Float value between 0.0
and 1.0
from this random number generator's sequence.
ReturnValue
Name | Description |
---|---|
Float
|
nextDouble
fun nextDouble(): Double
Returns the next pseudorandom, uniformly distributed Double value between 0.0
and 1.0
from this random number generator's sequence.
ReturnValue
Name | Description |
---|---|
Double
|
nextChar
fun nextChar(): Char
Returns the next pseudorandom, uniformly distributed Char value, from this random number generator's sequence.
ReturnValue
Name | Description |
---|---|
Char
|
nextEnum
fun <E : Enum<E>> nextEnum(): E
Returns a randomly selected enum entry of type E.
ReturnValue
Name | Description |
---|---|
E
|
nextEnum
fun <E : Enum<E>> nextEnum(enum: Class<E>): E
Returns a pseudo-randomly selected enum entry of type E.
Parameters
Name | Description |
---|---|
enum: Class<E>
|
ReturnValue
Name | Description |
---|---|
E
|
nextEnum
fun <E : Enum<E>> nextEnum(values: Array<E>): E
Returns a pseudo-randomly selected enum entry from an Array of E type values.
Parameters
Name | Description |
---|---|
values: Array<E>
|
ReturnValue
Name | Description |
---|---|
E
|
nextEnum
tailrec fun <E : Enum<E>> nextEnum(enum: Class<E>, predicate: (E)->Boolean): E
Returns a pseudo-randomly selected enum class of type E based on predicate for E.
Parameters
Name | Description |
---|---|
enum: Class<E>
|
|
predicate: (E)->Boolean
|
ReturnValue
Name | Description |
---|---|
E
|
nextEnum
fun <E : Enum<E>> nextEnum(excludeName: String): E
Returns a randomly selected enum entry of type E excluding a particular enum class by its name.
Parameters
Name | Description |
---|---|
excludeName: String
|
ReturnValue
Name | Description |
---|---|
E
|
nextUUID
fun nextUUID(): String
ReturnValue
Name | Description |
---|---|
String
|
randomSublist
fun <T> randomSublist(list: List<T>, size: Int, shuffled: Boolean): List<T>
Returns a view of the portion of the list
with pseudo-randomly generated fromIndex
and (possibly) toIndex
values.
Parameters
Name | Description |
---|---|
list: List<T>
|
|
size: Int
|
the desired size of the resulting list.
If |
shuffled: Boolean
|
if |
ReturnValue
Name | Description |
---|---|
List<T>
|
randomSublist
fun <T> randomSublist(list: List<T>, sizeRange: IntRange, shuffled: Boolean): List<T>
Returns a view of the portion of the list
with pseudo-randomly generated fromIndex
and (possibly) toIndex
values.
Parameters
Name | Description |
---|---|
list: List<T>
|
|
sizeRange: IntRange
|
the desired size range of the resulting list.
The |
shuffled: Boolean
|
if |
ReturnValue
Name | Description |
---|---|
List<T>
|
randomSubset
fun <T> randomSubset(set: Set<T>, size: Int, shuffled: Boolean): Set<T>
Returns a portion of the set
with pseudo-randomly generated fromIndex
and (possibly) toIndex
values.
Parameters
Name | Description |
---|---|
set: Set<T>
|
|
size: Int
|
the desired size of the resulting set.
If |
shuffled: Boolean
|
if |
ReturnValue
Name | Description |
---|---|
Set<T>
|
randomSubset
fun <T> randomSubset(set: Set<T>, sizeRange: IntRange, shuffled: Boolean): Set<T>
Returns a portion of the set
with pseudo-randomly generated fromIndex
and (possibly) toIndex
values.
Parameters
Name | Description |
---|---|
set: Set<T>
|
|
sizeRange: IntRange
|
the desired size range of the resulting list.
The |
shuffled: Boolean
|
if |
ReturnValue
Name | Description |
---|---|
Set<T>
|
randomPastDate
fun randomPastDate(): OffsetDateTime
Returns a pseudorandom, uniformly distributed OffsetDateTime value between Unix epoch (1970-01-01T00:00:00Z) (inclusive) and now (exclusive) using UTC zone offset
ReturnValue
Name | Description |
---|---|
OffsetDateTime
|
randomPastDate
fun randomPastDate(min: Instant): OffsetDateTime
Returns a pseudorandom, uniformly distributed OffsetDateTime value between min (inclusive) and now (exclusive) using UTC zone offset
Parameters
Name | Description |
---|---|
min: Instant
|
ReturnValue
Name | Description |
---|---|
OffsetDateTime
|
randomFutureDate
fun randomFutureDate(): OffsetDateTime
Returns a pseudorandom, uniformly distributed OffsetDateTime value between now (exclusive) and now + 50 years (inclusive) using UTC zone offset
ReturnValue
Name | Description |
---|---|
OffsetDateTime
|
randomFutureDate
fun randomFutureDate(max: Instant): OffsetDateTime
Returns a pseudorandom, uniformly distributed OffsetDateTime value between now (exclusive) and max (inclusive) using UTC zone offset
Parameters
Name | Description |
---|---|
max: Instant
|
ReturnValue
Name | Description |
---|---|
OffsetDateTime
|
randomDate
fun randomDate(min: Instant, max: Instant, zoneOffset: ZoneOffset): OffsetDateTime
Returns a pseudorandom, uniformly distributed OffsetDateTime value between min (inclusive) and max (inclusive) using the defined zoneOffset
Parameters
Name | Description |
---|---|
min: Instant
|
|
max: Instant
|
|
zoneOffset: ZoneOffset
|
ReturnValue
Name | Description |
---|---|
OffsetDateTime
|
Wrapper around Random that also contains some additional functions not covered by Random.
If two instances of this RandomService are created with the same seed, and the same sequence of method calls is made for each, then they will generate and return identical sequences of values.
Instances of RandomService are not cryptographically secure by default. Consider passing java.security.SecureRandom to the constructor of this RandomService to get a cryptographically secure pseudo-random generator.