class RandomProvider: IRandom, AbstractFakeDataProvider<RandomProvider>

Provides data-generator-like functionality for the functions of RandomService.

Fields

Name Description
protected category: Category

Category of this fake data provider class.

protected localUniqueDataProvider: LocalUniqueDataProvider<RandomProvider>

A LocalUniqueDataProvider instance that is used with this unique provider.

val unique: RandomProvider

An instance of T for generating unique values

val config: FakerConfig

Methods

clear

fun clear(key: Key)

Clears used unique values for the function key of this provider.

Parameters

Name Description
key: Key

ReturnValue

Name Description
Unit

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 true, and in lower-case otherwise

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: 24

numericalChars: Boolean

add additional numerical chars from 0 to 9 to the resulting string. Default: true

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: 24

locale: Locale

locale to use to generate the charset. Defaults to locale config value set for the faker instance.

indexChars: Boolean

add additional index chars to the resulting string, as defined in Character_Elements. Default: true

auxiliaryChars: Boolean

add additional auxiliary chars to the resulting string as defined in Character_Elements. Default: false

punctuationChars: Boolean
numericalChars: Boolean

add additional numerical chars from 0 to 9 to the resulting string Default: false

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 locale config value set for the faker instance.

indexChars: Boolean

add additional index chars to the resulting string, as defined in Character_Elements. Default: true

auxiliaryChars: Boolean

add additional auxiliary chars to the resulting string as defined in Character_Elements. Default: false

punctuationChars: Boolean
numericalChars: Boolean

add additional numerical chars from 0 to 9 to the resulting string Default: false

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.

NB! this method does not try to produce "unique" values via unique data provider.

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.

NB! when used with unique, the nextInt, which is used to get a random index of the enumValues of Ewill also use unique generation and will need to be reset via clear as well when needed.

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

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(vararg excludeName: String): E

Returns a randomly selected enum entry of type E excluding a particular enum class by its name.

NB! when used with unique, the nextInt, which is used to get a random index of the enumValues of Ewill also use unique generation and will need to be reset via clear as well when needed.

Parameters

Name Description
vararg excludeName: String

ReturnValue

Name Description
E

nextUUID

fun nextUUID(): String

Returns the next pseudorandom UUID as String taking the seed of this random.

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 size <= 0 then toIndex will also be randomly-generated.

shuffled: Boolean

if true the list will be shuffled before extracting the sublist

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 size of the returned list is the result of calling nextInt with the sizeRange. IF size <= 0 then toIndex will also be randomly-generated.

shuffled: Boolean

if true the list will be shuffled before extracting the sublist

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 size <= 0 then toIndex will also be randomly-generated.

shuffled: Boolean

if true the set will be shuffled before extracting the subset

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 size of the returned list is the result of calling nextInt with the sizeRange. IF size <= 0 then toIndex will also be randomly-generated.

shuffled: Boolean

if true the set will be shuffled before extracting the subset

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