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
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rand.R
\name{rand_bytes}
\alias{rand_bytes}
\alias{rand_num}
\title{Generate random bytes and numbers with OpenSSL}
\usage{
rand_bytes(n = 1)
rand_num(n = 1)
}
\arguments{
\item{n}{number of random bytes or numbers to generate}
}
\description{
this set of functions generates random bytes or numbers from OpenSSL. This
provides a cryptographically secure alternative to R's default random number generator.
\code{rand_bytes} generates \code{n} random cryptographically secure bytes
}
\examples{
rnd <- rand_bytes(10)
as.numeric(rnd)
as.character(rnd)
as.logical(rawToBits(rnd))
# bytes range from 0 to 255
rnd <- rand_bytes(100000)
hist(as.numeric(rnd), breaks=-1:255)
# Generate random doubles between 0 and 1
rand_num(5)
# Use CDF to map [0,1] into random draws from a distribution
x <- qnorm(rand_num(1000), mean=100, sd=15)
hist(x)
y <- qbinom(rand_num(1000), size=10, prob=0.3)
hist(y)
}
\references{
OpenSSL manual: \url{https://www.openssl.org/docs/man1.1.1/man3/RAND_bytes.html}
}
|