Random character strings
rand_chars.RdGenerate a vector of random character strings.
Usage
rand_chars(
length = 1L,
nchars = 6L,
as_raw = c(33:47, 91:95, 123:126, 49:57, 65:90, 97:122),
replace = TRUE
)Arguments
- length
(Scalar integer:
[1, Inf])
The number of elements in the character vector.- nchars
(Scalar integer:
[1, Inf])
The number of characters in each string.- as_raw
(Integer vector: See 'Details')
Integers to be converted torawtype and then back to character.- replace
(Scalar logical:
c(TRUE, FALSE))
Whether or not characters can be repeated in each string.TRUE(default) samples with replacement.
Details
Below is the result of converting integers to raw type and then back to character.
33:47-!\"#$%&'()*+,-./91:95-[]^_123:126-{|}~49:57-12345678965:90-ABCDEFGHIJKLMNOPQRSTUVWXYZ97:122-abcdefghijklmnopqrstuvwxyz
See also
Other simulate:
insert_value(),
sim_character(),
sim_data.frame(),
sim_date(),
sim_datetime(),
sim_double(),
sim_factor(),
sim_integer(),
sim_logical()
Examples
#----------------------------------------------------------------------------
# rand_chars() examples
#----------------------------------------------------------------------------
library(bkcheck)
rand_chars()
#> [1] "%zKbAk"
rand_chars(10)
#> [1] "d$ABJ'" "8Tk)|*" "8A\\SW|" "!kARMf" "1D(9x4" "OpB\"#E" "if&|^\""
#> [8] "eGf4l," "UHIg2a" ".%q\\-9"
rand_chars(length = 6, nchars = 2)
#> [1] "rw" "8j" "V+" "9C" "'}" "Am"