Generate a random vector of desired type

random_vector(size, type, custom_generator = NULL, unique = FALSE, ...)

Arguments

size

integer, vector length

type

"integer", "string", "boolean", "date", "time", "datetime" or "numeric" type of vector values. If custom generator provided, should be set to "custom".

custom_generator

function or string, custom value generator. Can be a function or a string with function name. Default: NULL

unique

boolean, should the output contain only unique values. Default: FALSE.

...

arguments passed to function responsible for generating values. Check random_integer, random_string, random_boolean and random_numeric for details

Value

vector of random values of chosen type

Examples

random_vector(5, "boolean")
#> [1]  TRUE  TRUE FALSE  TRUE FALSE
random_vector(10, "numeric", min = 1.5, max = 5)
#>  [1] 3.212620 4.033722 2.698047 4.007251 2.135780 1.693397 2.954284 4.920425
#>  [9] 3.408869 1.778942
random_vector(4, "string", length = 4, pattern = "[ACGT]")
#> [1] "AGCA" "TGAC" "CCTT" "ACAC"
random_vector(2, "integer", max = 10)
#> [1] 0 9

# custom generator
custom_generator <- function() sample(c("A", "B"), 1)
random_vector(3, type = "custom", custom_generator = custom_generator)
#> [1] "A" "A" "B"