File tree Expand file tree Collapse file tree 1 file changed +6
-29
lines changed Expand file tree Collapse file tree 1 file changed +6
-29
lines changed Original file line number Diff line number Diff line change 1- // Original code adapted from Robert Kieffer.
2- // details at https://github.com/broofa/node-uuid
3-
4-
51( function ( ) {
6- var _global = this ;
7-
8- var mathRNG , whatwgRNG ;
9-
10- // NOTE: Math.random() does not guarantee "cryptographic quality"
11- mathRNG = function ( size ) {
12- var bytes = new Buffer ( size ) ;
13- var r ;
14-
15- for ( var i = 0 , r ; i < size ; i ++ ) {
16- if ( ( i & 0x03 ) == 0 ) r = Math . random ( ) * 0x100000000 ;
17- bytes [ i ] = r >>> ( ( i & 0x03 ) << 3 ) & 0xff ;
18- }
19-
2+ module . exports = function ( size ) {
3+ var bytes = new Buffer ( size ) ; //in browserify, this is an extended Uint8Array
4+ /* This will not work in older browsers.
5+ * See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
6+ */
7+ crypto . getRandomValues ( bytes ) ;
208 return bytes ;
219 }
22-
23- if ( _global . crypto && crypto . getRandomValues ) {
24- whatwgRNG = function ( size ) {
25- var bytes = new Buffer ( size ) ; //in browserify, this is an extended Uint8Array
26- crypto . getRandomValues ( bytes ) ;
27- return bytes ;
28- }
29- }
30-
31- module . exports = whatwgRNG || mathRNG ;
32-
3310} ( ) )
You can’t perform that action at this time.
0 commit comments