The rand_bytes
function binds to RAND_bytes
in OpenSSL to generate cryptographically strong pseudo-random bytes. See
the OpenSSL documentation for what this means.
[1] d8 1a dc 24 14 75 82 7e e5 d8
Bytes are 8 bit and hence can have 2^8 = 256 possible
values.
[1] 216 26 220 36 20 117 130 126 229 216
Each random byte can be decomposed into 8 random bits (booleans)
[1] TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE
rand_num is a simple (2 lines) wrapper to
rand_bytes to generate random numbers (doubles) between 0
and 1.
[1] 0.4093016 0.6469595 0.7696102 0.6055394 0.3985970 0.7130491 0.6069492
[8] 0.3375967 0.9527642 0.5948772
To map random draws from [0,1] into a probability density, we can use
a Cumulative
Distribution Function. For example we can combine qnorm
and rand_num to simulate rnorm:
Same for discrete distributions: