bytes = crypto.random(n)
hexa = crypto.random(n, '-hex')
| Parameter | Description |
|---|---|
| n | an integer between 1 and 1048576: number of random bytes. |
| '-hex' | return the bytes as a hexadecimal character vector instead of uint8. |
| Parameter | Description |
|---|---|
| bytes | a uint8 row vector of n secure random bytes. |
| hexa | a character vector: 2 * n lowercase hexadecimal characters. |
crypto.random returns random bytes from the operating system secure random source (BCryptGenRandom on Windows, /dev/urandom on other systems). Use it for keys, nonces and salts. Unlike rand, its output is unpredictable and must not be seeded.
key = crypto.random(32)
nonce = crypto.random(24, '-hex')
| Version | Description |
|---|---|
| 2.0.0 | initial version |