Skip to contents

Generate 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 to raw type 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.

Value

character

Details

Below is the result of converting integers to raw type and then back to character.

  • 33:47 - !\"#$%&'()*+,-./

  • 91:95 - []^_

  • 123:126 - {|}~

  • 49:57 - 123456789

  • 65:90 - ABCDEFGHIJKLMNOPQRSTUVWXYZ

  • 97:122 - abcdefghijklmnopqrstuvwxyz

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"