mozilla
Your Search Results

    window.crypto.getRandomValues Redirect 1

    « DOM Reference

    This is an experimental technology
    Because this technology's specification has not stabilized, check the compatibility table for the proper prefixes to use in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the spec changes.

    This method lets you get cryptographically random values.

    Syntax

    window.crypto.getRandomValues(typedArray);

    Parameters

    Parameter Description
    typedArray Integer-based TypedArray. All elements in the array are going to be overridden with random numbers.

    Description

    If you provide an integer-based TypedArray (i.e. Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, or Uint32Array), the function is going fill the array with cryptographically random numbers. The browser is supposed to be using a strong (pseudo) random number generator. Because the browser probably only has a limited amount of entropy, the method is free to throw the QuotaExceededError, if too much entropy is drained.

    Example

    /* assuming that window.crypto.getRandomValues is available */
    
    var array = new Uint32Array(10);
    window.crypto.getRandomValues(array);
    
    console.log("Your lucky numbers:");
    for (var i = 0; i < array.length; i++) {
        console.log(array[i]);
    }
    

    Browser Compatibility

    Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
    Basic support 11.0 WebKit bug 22049 21.0 11.0 15.0 3.1
    Feature Android Browser Chrome (as App) Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari
    Basic support Not supported 23 21.0 Not supported Not supported iOS 6

    Specification

    See also

    Document Tags and Contributors

    Contributors to this page: Sheppy
    Last updated by: Sheppy,
    Hide Sidebar