rcrypto {cryptorng}R Documentation

Generate random numbers using platform-specific cryptographically secure pseudorandom number generators

Description

Generate random numbers using platform-specific cryptographically secure pseudorandom number generators

Usage

rcrypto(n, type = "raw")

Arguments

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'

'raw'

Uniform random bytes from the CSPRNG returned as a raw vector

'chr'

Uniform random bytes from the CRPRNG returned as a hexadecimal string

'lgl'

Uniform random bytes return as random logical values

'int'

Combines 4 random bytes to create uniform random integers. This output is further filtered to remove any NA values which may occur

'dbl'

Combines 8 random bytes to create uniform random numbers in the range [0, 1)

Value

Depending on the type argument: a hexadecimal string, a raw vector, a logical vector, an integer vector or a numeric vector.

Details for 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.

Details for 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.

Platform notes

The method used for generating random values varies depending on the operating system (OS):

All these random number generators are internally seeded by the OS using entropy gathered from multiple sources and are considered cryptographically secure.

Examples

rcrypto(16, type = 'raw')
rcrypto(16, type = 'chr')
rcrypto(16, type = 'lgl')
rcrypto(16, type = 'int')
rcrypto(16, type = 'dbl')

[Package cryptorng version 0.1.4 Index]