Skip to main content
Version: 3.13.0

Crypto.getRandomValues()

The Crypto.getRandomValues() method lets you get cryptographically strong random values. The array given as the parameter is filled with random numbers (random in its cryptographic meaning).

Syntax

getRandomValues(typedArray)

Parameters

  • typedArray
    • : An integer-based TypedArray, that is one of: Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, BigUint64Array (but not Float32Array nor Float64Array). All elements in the array will be overwritten with random numbers.

Return value

The same array passed as typedArray but with its contents replaced with the newly generated random numbers. Note that typedArray is modified in-place, and no copy is made.

Exceptions

  • QuotaExceededError
    • : Thrown if the byteLength of typedArray exceeds 65,536.