the length of the Uint8Array to generate
a function used to generate the random bytes, defaults to generateRandomBytesUnchecked.
Generate a Uint8Array of the specified length containing a cryptographically-random series of bytes. See generateRandomBytes for a safer alternative.
Generated using TypeDoc
Generate a Uint8Array of the specified length containing a cryptographically-random series of bytes.
For safety, this function first verifies that the provided
generate
function produces unique results across two evaluations; by default, this verifies that thecrypto.getRandomValues
function provided by the JavaScript environment appears to be producing random values.While this validation can't prevent a compromised environment from producing attacker-known entropy, it may help to prevent software defects in unusual environments (e.g. React Native) from impacting end-user security.
An
Error
is thrown if this validation fails, otherwise, theUint8Array
produced by the first evaluation is returned.