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] 3a c0 78 72 ba fc a5 f2 5d cb
Bytes are 8 bit and hence can have 2^8 = 256 possible
values.
[1] 58 192 120 114 186 252 165 242 93 203
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.76199241 0.81311330 0.85694811 0.83711560 0.45152014 0.09553275
[7] 0.67628592 0.15732502 0.42063247 0.94646456
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: