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

To guarantee enough performance, implementations are not using a truly random number generator, but they are using a pseudo-random number generator seeded with a value with enough entropy. The PRNG used differs from one implementation to the other but is suitable for cryptographic usages. Implementations are also required to use a seed with enough entropy, like a system-level entropy source.




Is an integer-based TypedArray, that is an Int8Array, a Uint8Array, an Int16Array, a Uint16Array, an Int32Array, or a Uint32Array. All elements in the array are going to be overridden with random numbers.



/* assuming that window.crypto.getRandomValues is available */

var array = new Uint32Array(10);

console.log("Your lucky numbers:");
for (var i = 0; i < array.length; i++) {


Specification Status Comment
Web Cryptography API Candidate Recommendation Initial definition

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 Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support No support 23.0 21.0 11.0 No support 6

See also

Document Tags and Contributors

 Last updated by: mitar,