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] 93 d8 25 e0 b0 d2 5d ae 4a d4
Bytes are 8 bit and hence can have 2^8 = 256 possible
values.
[1] 147 216 37 224 176 210 93 174 74 212
Each random byte can be decomposed into 8 random bits (booleans)
[1] TRUE TRUE TRUE FALSE FALSE TRUE TRUE FALSE
rand_num is a simple (2 lines) wrapper to
rand_bytes to generate random numbers (doubles) between 0
and 1.
[1] 0.83953944 0.29844543 0.39407164 0.08146542 0.04298937 0.92493635
[7] 0.60642847 0.68820314 0.85529818 0.60618675
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: