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] 79 1d b1 2d 50 5c bd b2 3a 39
Bytes are 8 bit and hence can have 2^8 = 256
possible
values.
[1] 121 29 177 45 80 92 189 178 58 57
Each random byte can be decomposed into 8 random bits (booleans)
[1] FALSE TRUE TRUE TRUE TRUE TRUE FALSE TRUE
rand_num
is a simple (2 lines) wrapper to
rand_bytes
to generate random numbers (doubles) between 0
and 1.
[1] 0.63794432 0.05711832 0.96294654 0.29554318 0.25221062 0.02946088
[7] 0.32058523 0.45198640 0.90573517 0.86412167
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: