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] 8f 44 d8 7b ee 82 dd 01 3a 17
Bytes are 8 bit and hence can have 2^8 = 256 possible
values.
[1] 143 68 216 123 238 130 221 1 58 23
Each random byte can be decomposed into 8 random bits (booleans)
[1] TRUE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
rand_num is a simple (2 lines) wrapper to
rand_bytes to generate random numbers (doubles) between 0
and 1.
[1] 0.5446882 0.3167687 0.6523388 0.2466618 0.9250405 0.5831803 0.5286141
[8] 0.9634572 0.9803327 0.1321982
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: