seedrandom
Advanced tools
Comparing version 2.3.6 to 2.3.7
{ | ||
"name": "seedrandom", | ||
"version": "2.3.6", | ||
"description": "Seeded random number generator for Javascript.", | ||
"main": "seedrandom.js", | ||
"license": "MIT", | ||
"keywords": [ | ||
"random", | ||
"seed", | ||
"crypto" | ||
], | ||
"ignore": [], | ||
"devDependencies": { | ||
@@ -6,0 +13,0 @@ "qunit": "latest", |
@@ -45,2 +45,17 @@ module.exports = function(grunt) { | ||
}, | ||
mochacov: { | ||
options: { | ||
files: ['test/cryptotest.js', 'test/nodetest.js'] | ||
}, | ||
coverage: { | ||
options: { | ||
coveralls: true | ||
} | ||
}, | ||
test: { | ||
options: { | ||
reporter: 'dot' | ||
} | ||
} | ||
}, | ||
release: { | ||
@@ -53,10 +68,12 @@ options: { | ||
grunt.loadNpmTasks('grunt-bowercopy'); | ||
grunt.loadNpmTasks('grunt-contrib-qunit'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-qunit'); | ||
grunt.loadNpmTasks('grunt-mocha-cov'); | ||
grunt.loadNpmTasks('grunt-release'); | ||
grunt.loadNpmTasks('grunt-bowercopy'); | ||
grunt.loadNpmTasks('grunt-sed'); | ||
grunt.registerTask("default", ["uglify", "sed", "qunit"]); | ||
grunt.registerTask("default", ["uglify", "sed", "qunit", "mochacov:test"]); | ||
grunt.registerTask("travis", ["default", "mochacov:coverage"]); | ||
}; | ||
{ | ||
"name": "seedrandom", | ||
"version": "2.3.6", | ||
"version": "2.3.7", | ||
"description": "Seeded random number generator for Javascript.", | ||
@@ -12,3 +12,3 @@ "main": "seedrandom.js", | ||
"scripts": { | ||
"test": "grunt" | ||
"test": "grunt travis" | ||
}, | ||
@@ -25,12 +25,22 @@ "repository": { | ||
"homepage": "http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html", | ||
"config": { | ||
"blanket": { | ||
"pattern": [ | ||
"seedrandom.js" | ||
] | ||
} | ||
}, | ||
"devDependencies": { | ||
"blanket": "latest", | ||
"grunt": "latest", | ||
"grunt-bowercopy": "latest", | ||
"grunt-cli": "latest", | ||
"grunt-contrib-qunit": "latest", | ||
"grunt-contrib-uglify": "latest", | ||
"grunt-contrib-qunit": "latest", | ||
"grunt-mocha-cov": "latest", | ||
"grunt-release": "latest", | ||
"grunt-sed": "latest", | ||
"phantomjs": "latest" | ||
"phantomjs": "latest", | ||
"proxyquire": "git://github.com/davidbau/proxyquire.git#nullstub" | ||
} | ||
} |
@@ -9,5 +9,5 @@ seedrandom.js | ||
version 2.3.6<br> | ||
Author: David Bau<br> | ||
Date: 2014 May 14 | ||
version 2.3.7 | ||
Author: David Bau | ||
Date: 2014 Sep 18 | ||
@@ -21,3 +21,3 @@ Can be used as a plain script, a node.js module or an AMD module. | ||
<pre> | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.6/seedrandom.min.js> | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.7/seedrandom.min.js> | ||
</script> | ||
@@ -92,7 +92,7 @@ </pre> | ||
Network seeding via a script tag | ||
-------------------------------- | ||
Network seeding | ||
--------------- | ||
<pre> | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.6/seedrandom.min.js> | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.7/seedrandom.min.js> | ||
</script> | ||
@@ -102,5 +102,22 @@ <!-- Seeds using urandom bits from a server. --> | ||
</script> | ||
<!-- Seeds mixing in random.org bits --> | ||
<script> | ||
(function(x, u, s){ | ||
try { | ||
// Make a synchronous request to random.org. | ||
x.open('GET', u, false); | ||
x.send(); | ||
s = unescape(x.response.trim().replace(/^|\s/g, '%')); | ||
} finally { | ||
// Seed with the response, or autoseed on failure. | ||
Math.seedrandom(s, !!s); | ||
} | ||
})(new XMLHttpRequest, 'https://www.random.org/integers/' + | ||
'?num=256&min=0&max=255&col=1&base=16&format=plain&rnd=new'); | ||
</script> | ||
</pre> | ||
Examples of manipulating the seed for various purposes: | ||
Reseeding using user input | ||
-------------------------- | ||
@@ -142,2 +159,3 @@ <pre> | ||
The random number sequence is the same as version 1.0 for string seeds. | ||
* Version 2.0 changed the sequence for non-string seeds. | ||
@@ -150,2 +168,3 @@ * Version 2.1 speeds seeding and uses window.crypto to autoseed if present. | ||
* Version 2.3.6 adds a readable options object argument. | ||
* Version 2.3.7 adds support for node.js crypto (contributed by cdt1500). | ||
@@ -188,3 +207,3 @@ The standard ARC4 key scheduler cycles short keys, which means that | ||
Copyright (c)2014 David Bau. | ||
Copyright 2014 David Bau. | ||
@@ -191,0 +210,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
@@ -8,5 +8,5 @@ /** | ||
version 2.3.6<br> | ||
Author: David Bau<br> | ||
Date: 2014 May 14 | ||
version 2.3.7 | ||
Author: David Bau | ||
Date: 2014 Sep 18 | ||
@@ -18,3 +18,3 @@ Can be used as a plain script, a node.js module or an AMD module. | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.6/seedrandom.min.js> | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.7/seedrandom.min.js> | ||
</script> | ||
@@ -78,7 +78,8 @@ | ||
Network seeding via a script tag | ||
-------------------------------- | ||
Network seeding | ||
--------------- | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.6/seedrandom.min.js> | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.7/seedrandom.min.js> | ||
</script> | ||
<!-- Seeds using urandom bits from a server. --> | ||
@@ -88,4 +89,21 @@ <script src=//jsonlib.appspot.com/urandom?callback=Math.seedrandom"> | ||
Examples of manipulating the seed for various purposes: | ||
<!-- Seeds mixing in random.org bits --> | ||
<script> | ||
(function(x, u, s){ | ||
try { | ||
// Make a synchronous request to random.org. | ||
x.open('GET', u, false); | ||
x.send(); | ||
s = unescape(x.response.trim().replace(/^|\s/g, '%')); | ||
} finally { | ||
// Seed with the response, or autoseed on failure. | ||
Math.seedrandom(s, !!s); | ||
} | ||
})(new XMLHttpRequest, 'https://www.random.org/integers/' + | ||
'?num=256&min=0&max=255&col=1&base=16&format=plain&rnd=new'); | ||
</script> | ||
Reseeding using user input | ||
-------------------------- | ||
var seed = Math.seedrandom(); // Use prng with an automatic seed. | ||
@@ -101,3 +119,3 @@ document.write(Math.random()); // Pretty much unpredictable x. | ||
t.push([e.pageX, e.pageY, +new Date]); | ||
if (t.length < count) { return; } | ||
if (t.length < count) { return; } | ||
document.removeEventListener(event, w); | ||
@@ -130,2 +148,3 @@ Math.seedrandom(t, { entropy: true }); | ||
* Version 2.3.6 adds a readable options object argument. | ||
* Version 2.3.7 adds support for node.js crypto (contributed by cdt1500). | ||
@@ -168,3 +187,3 @@ The standard ARC4 key scheduler cycles short keys, which means that | ||
Copyright (c)2014 David Bau. | ||
Copyright 2014 David Bau. | ||
@@ -205,2 +224,3 @@ Permission is hereby granted, free of charge, to any person obtaining | ||
mask = width - 1, | ||
crypto; | ||
@@ -294,4 +314,5 @@ // | ||
return r; | ||
// For robust unpredictability discard an initial batch of values. | ||
// See http://www.rsa.com/rsalabs/node.asp?id=2009 | ||
// For robust unpredictability, the function call below automatically | ||
// discards an initial batch of values. This is called RC4-drop[256]. | ||
// See http://google.com/search?q=rsa+fluhrer+response&btnI | ||
})(width); | ||
@@ -337,6 +358,8 @@ } | ||
return tostring(seed); | ||
} catch (e) { | ||
} catch (e1) { try { | ||
return tostring(nodecrypto.randomBytes(width)); | ||
} catch (e2) { | ||
return [+new Date, global, (seed = global.navigator) && seed.plugins, | ||
global.screen, tostring(pool)]; | ||
} | ||
global.screen, tostring(pool)]; | ||
} } | ||
} | ||
@@ -355,3 +378,3 @@ | ||
// from the built-in RNG into the entropy pool. Because we do | ||
// not want to intefere with determinstic PRNG state later, | ||
// not want to interfere with deterministic PRNG state later, | ||
// seedrandom will not call math.random on its own again after | ||
@@ -363,3 +386,3 @@ // initialization. | ||
// | ||
// Nodejs and AMD support: export the implemenation as a module using | ||
// Nodejs and AMD support: export the implementation as a module using | ||
// either convention. | ||
@@ -369,2 +392,6 @@ // | ||
module.exports = impl; | ||
try { | ||
// When in node.js, try using crypto package for autoseeding. | ||
nodecrypto = require('crypto'); | ||
} catch (ex) {} | ||
} else if (define && define.amd) { | ||
@@ -374,2 +401,6 @@ define(function() { return impl; }); | ||
// | ||
// Node.js native crypto support. | ||
// | ||
// End anonymous scope, and pass initial values. | ||
@@ -376,0 +407,0 @@ })( |
@@ -1,1 +0,1 @@ | ||
!function(a,b,c,d,e,f,g,h,i){function j(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=r&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=r&f+1],c=c*d+h[r&(h[f]=h[g=r&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function k(a,b){var c,d=[],e=typeof a;if(b&&"object"==e)for(c in a)try{d.push(k(a[c],b-1))}catch(f){}return d.length?d:"string"==e?a:a+"\0"}function l(a,b){for(var c,d=a+"",e=0;e<d.length;)b[r&e]=r&(c^=19*b[r&e])+d.charCodeAt(e++);return n(b)}function m(c){try{return a.crypto.getRandomValues(c=new Uint8Array(d)),n(c)}catch(e){return[+new Date,a,(c=a.navigator)&&c.plugins,a.screen,n(b)]}}function n(a){return String.fromCharCode.apply(0,a)}var o=c.pow(d,e),p=c.pow(2,f),q=2*p,r=d-1,s=c["seed"+i]=function(a,f,g){var h=[];f=1==f?{entropy:!0}:f||{};var r=l(k(f.entropy?[a,n(b)]:null==a?m():a,3),h),s=new j(h);return l(n(s.S),b),(f.pass||g||function(a,b,d){return d?(c[i]=a,b):a})(function(){for(var a=s.g(e),b=o,c=0;p>a;)a=(a+c)*d,b*=d,c=s.g(1);for(;a>=q;)a/=2,b/=2,c>>>=1;return(a+c)/b},r,"global"in f?f.global:this==c)};l(c[i](),b),g&&g.exports?g.exports=s:h&&h.amd&&h(function(){return s})}(this,[],Math,256,6,52,"object"==typeof module&&module,"function"==typeof define&&define,"random"); | ||
!function(a,b,c,d,e,f,g,h,i){function j(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=r&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=r&f+1],c=c*d+h[r&(h[f]=h[g=r&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function k(a,b){var c,d=[],e=typeof a;if(b&&"object"==e)for(c in a)try{d.push(k(a[c],b-1))}catch(f){}return d.length?d:"string"==e?a:a+"\0"}function l(a,b){for(var c,d=a+"",e=0;e<d.length;)b[r&e]=r&(c^=19*b[r&e])+d.charCodeAt(e++);return n(b)}function m(c){try{return a.crypto.getRandomValues(c=new Uint8Array(d)),n(c)}catch(e){try{return n(nodecrypto.randomBytes(d))}catch(f){return[+new Date,a,(c=a.navigator)&&c.plugins,a.screen,n(b)]}}}function n(a){return String.fromCharCode.apply(0,a)}var o=c.pow(d,e),p=c.pow(2,f),q=2*p,r=d-1;if(impl=c["seed"+i]=function(a,f,g){var h=[];f=1==f?{entropy:!0}:f||{};var r=l(k(f.entropy?[a,n(b)]:null==a?m():a,3),h),s=new j(h);return l(n(s.S),b),(f.pass||g||function(a,b,d){return d?(c[i]=a,b):a})(function(){for(var a=s.g(e),b=o,c=0;p>a;)a=(a+c)*d,b*=d,c=s.g(1);for(;a>=q;)a/=2,b/=2,c>>>=1;return(a+c)/b},r,"global"in f?f.global:this==c)},l(c[i](),b),g&&g.exports){g.exports=impl;try{nodecrypto=require("crypto")}catch(s){}}else h&&h.amd&&h(function(){return impl})}(this,[],Math,256,6,52,"object"==typeof module&&module,"function"==typeof define&&define,"random"); |
@@ -1,2 +0,3 @@ | ||
var seedrandom = require('../seedrandom') | ||
#!/usr/bin/env node | ||
var seedrandom = require('../seedrandom'); | ||
@@ -27,5 +28,6 @@ // process.on('SIGPIPE', process.exit); | ||
buf = new Buffer(bufsize * 4), | ||
prng = seedrandom(0); | ||
prng = seedrandom(0), | ||
count = parseInt(process.argv[2]) || Infinity; | ||
function dowrite() { | ||
while (true) { | ||
while (count > 0) { | ||
for (var j = 0; j < bufsize; ++j) { | ||
@@ -36,2 +38,3 @@ buf.writeUInt32BE(Math.floor( | ||
} | ||
count -= bufsize * 32; | ||
if (!process.stdout.write(buf)) { | ||
@@ -38,0 +41,0 @@ process.stdout.once('drain', function() { setTimeout(dowrite, 0) }); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
204053
22
4657
222
11
1
2