Initial commit
[yaffs-website] / node_modules / uuid / rng-browser.js
1
2 var rng;
3
4 var crypto = global.crypto || global.msCrypto; // for IE 11
5 if (crypto && crypto.getRandomValues) {
6   // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto
7   // Moderately fast, high quality
8   var _rnds8 = new Uint8Array(16);
9   rng = function whatwgRNG() {
10     crypto.getRandomValues(_rnds8);
11     return _rnds8;
12   };
13 }
14
15 if (!rng) {
16   // Math.random()-based (RNG)
17   //
18   // If all else fails, use Math.random().  It's fast, but is of unspecified
19   // quality.
20   var  _rnds = new Array(16);
21   rng = function() {
22     for (var i = 0, r; i < 16; i++) {
23       if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
24       _rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
25     }
26
27     return _rnds;
28   };
29 }
30
31 module.exports = rng;
32