Title: | Access System Cryptographic Pseudorandom Number Generators |
---|---|
Description: | Generate random numbers from the Cryptographically Secure Pseudorandom Number Generator (CSPRNG) provided by the underlying operating system. System CSPRNGs are seeded internally by the OS with entropy it gathers from the system hardware. The following system functions are used: arc4random_buf() on macOS and BSD; BCryptgenRandom() on Windows; Sys_getrandom() on Linux. |
Authors: | Mike Cheng [aut, cre, cph] |
Maintainer: | Mike Cheng <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.4 |
Built: | 2024-10-29 05:47:14 UTC |
Source: | https://github.com/coolbutuseless/cryptorng |
Generate random numbers using platform-specific cryptographically secure pseudorandom number generators
rcrypto(n, type = "raw")
rcrypto(n, type = "raw")
n |
Number of random numbers to generate. Note: if the entropy pool is exhausted on your system it may not be able to provide the requested number of bytes - in this case an error is thrown. |
type |
Type of returned values - 'raw', 'chr', 'lgl', 'int' or 'dbl'. Default: 'raw'
|
Depending on the type
argument: a hexadecimal string, a
raw vector, a logical vector, an integer vector or a numeric vector.
type = 'dbl'
An 8-byte double-precision floating point number is obtained by first
concatenating 8 random bytes into an 8-byte unsigned integer (i.e. uint64_t
).
This uint64_t
value is converted to an 8-byte double using:
(x >> 11) * 0x1.0p-53
.
type = 'int'
A 4-byte random R integer value is obtained by concatenating 4 random bytes.
These integer values are then filtered to exclude the special NA_integer
value used by R.
The method used for generating random values varies depending on the operating system (OS):
For macOS and BSDs: arc4random_buf()
For linux: syscall(SYS_getrandom())
For win32: BCryptGenRandom()
All these random number generators are internally seeded by the OS using entropy gathered from multiple sources and are considered cryptographically secure.
rcrypto(16, type = 'raw') rcrypto(16, type = 'chr') rcrypto(16, type = 'lgl') rcrypto(16, type = 'int') rcrypto(16, type = 'dbl')
rcrypto(16, type = 'raw') rcrypto(16, type = 'chr') rcrypto(16, type = 'lgl') rcrypto(16, type = 'int') rcrypto(16, type = 'dbl')