Strictly not for use in statistical analysis. Non-reproducible and with unknown statistical properties. Provides an alternative source of randomness from the Mbed TLS library for purposes such as cryptographic key generation. Mbed TLS uses a block-cipher in counter mode operation, as defined in NIST SP800-90A: Recommendation for Random Number Generation Using Deterministic Random Bit Generators. The implementation uses AES-256 as the underlying block cipher, with a derivation function, and an entropy collector combining entropy from multiple sources including at least one strong entropy source.

random(n = 1L, convert = TRUE)

Arguments

n

[default 1L] integer random bytes to generate (from 0 to 1024).

convert

[default TRUE] logical FALSE to return a raw vector, or TRUE to return the hex representation of the bytes as a character string.

Value

A length 'n' raw vector, or length one vector of '2n' random characters, depending on the value of 'convert' supplied.

Details

If 'n' is non-integer, it will be coerced to integer; if a vector, only the first element will be used.

Note

Results obtained are independent of and do not alter the state of R's own pseudo-random number generators.

Examples

random()
#> [1] "29"
random(8L)
#> [1] "15c414ba31e27f22"
random(n = 8L, convert = FALSE)
#> [1] c0 74 85 78 a1 cf 2b 21