Aliases: rand_bytes rand_num
Keywords:
### ** Examples rnd <- rand_bytes(10) as.numeric(rnd)
[1] 17 115 4 66 26 230 54 225 218 161
as.character(rnd)
[1] "11" "73" "04" "42" "1a" "e6" "36" "e1" "da" "a1"
as.logical(rawToBits(rnd))
[1] TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE TRUE TRUE FALSE FALSE [13] TRUE TRUE TRUE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE [25] FALSE TRUE FALSE FALSE FALSE FALSE TRUE FALSE FALSE TRUE FALSE TRUE [37] TRUE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE TRUE TRUE TRUE [49] FALSE TRUE TRUE FALSE TRUE TRUE FALSE FALSE TRUE FALSE FALSE FALSE [61] FALSE TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE FALSE TRUE TRUE [73] TRUE FALSE FALSE FALSE FALSE TRUE FALSE TRUE
# 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)
[1] 0.08016873 0.88763859 0.94150921 0.53699880 0.65834754
# 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)