1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/random.R
\name{stri_rand_strings}
\alias{stri_rand_strings}
\title{Generate Random Strings}
\usage{
stri_rand_strings(n, length, pattern = "[A-Za-z0-9]")
}
\arguments{
\item{n}{single integer, number of observations}
\item{length}{integer vector, desired string lengths}
\item{pattern}{character vector specifying character classes to draw
elements from, see \link{stringi-search-charclass}}
}
\value{
Returns a character vector.
}
\description{
Generates (pseudo)random strings of desired lengths.
}
\details{
Vectorized over \code{length} and \code{pattern}.
If length of \code{length} or \code{pattern} is greater than \code{n},
then redundant elements are ignored. Otherwise,
these vectors are recycled if necessary.
This operation may result in non-Unicode-normalized
strings and may give peculiar outputs for bidirectional strings.
Sampling of code points from the set specified by \code{pattern}
is always done with replacement and each code point appears with equal
probability.
}
\examples{
stri_rand_strings(5, 10) # 5 strings of length 10
stri_rand_strings(5, sample(1:10, 5, replace=TRUE)) # 5 strings of random lengths
stri_rand_strings(10, 5, '[\\\\p{script=latin}&\\\\p{Ll}]') # small letters from the Latin script
# generate n random passwords of length in [8, 14]
# consisting of at least one digit, small and big ASCII letter:
n <- 10
stri_rand_shuffle(stri_paste(
stri_rand_strings(n, 1, '[0-9]'),
stri_rand_strings(n, 1, '[a-z]'),
stri_rand_strings(n, 1, '[A-Z]'),
stri_rand_strings(n, sample(5:11, 5, replace=TRUE), '[a-zA-Z0-9]')
))
}
\seealso{
The official online manual of \pkg{stringi} at \url{https://stringi.gagolewski.com/}
Gagolewski M., \pkg{stringi}: Fast and portable character string processing in R, \emph{Journal of Statistical Software} 103(2), 2022, 1-59, \doi{10.18637/jss.v103.i02}
Other random:
\code{\link{stri_rand_lipsum}()},
\code{\link{stri_rand_shuffle}()}
}
\concept{random}
\author{
\href{https://www.gagolewski.com/}{Marek Gagolewski} and other contributors
}
|