seedrandom
Advanced tools
Comparing version 2.4.4 to 3.0.0
{ | ||
"name": "seedrandom", | ||
"version": "2.4.4", | ||
"version": "3.0.0", | ||
"description": "Seeded random number generator for Javascript", | ||
@@ -5,0 +5,0 @@ "repository": "davidbau/seedrandom", |
@@ -14,6 +14,6 @@ // A port of an algorithm by Johannes Baagøe <baagoe@baagoe.com>, 2010 | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
@@ -83,3 +83,3 @@ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
var mash = function(data) { | ||
data = data.toString(); | ||
data = String(data); | ||
for (var i = 0; i < data.length; i++) { | ||
@@ -86,0 +86,0 @@ n += data.charCodeAt(i); |
@@ -1,1 +0,1 @@ | ||
!function(n,t,e){function o(n){var s,t=this,e=(s=4022871197,function(n){n=n.toString();for(var t=0;t<n.length;t++){var e=.02519603282416938*(s+=n.charCodeAt(t));e-=s=e>>>0,s=(e*=s)>>>0,s+=4294967296*(e-=s)}return 2.3283064365386963e-10*(s>>>0)});t.next=function(){var n=2091639*t.s0+2.3283064365386963e-10*t.c;return t.s0=t.s1,t.s1=t.s2,t.s2=n-(t.c=0|n)},t.c=1,t.s0=e(" "),t.s1=e(" "),t.s2=e(" "),t.s0-=e(n),t.s0<0&&(t.s0+=1),t.s1-=e(n),t.s1<0&&(t.s1+=1),t.s2-=e(n),t.s2<0&&(t.s2+=1),e=null}function u(n,t){return t.c=n.c,t.s0=n.s0,t.s1=n.s1,t.s2=n.s2,t}function s(n,t){var e=new o(n),s=t&&t.state,r=e.next;return r.int32=function(){return 4294967296*e.next()|0},r.double=function(){return r()+11102230246251565e-32*(2097152*r()|0)},r.quick=r,s&&("object"==typeof s&&u(s,e),r.state=function(){return u(e,{})}),r}t&&t.exports?t.exports=s:e&&e.amd?e(function(){return s}):this.alea=s}(0,"object"==typeof module&&module,"function"==typeof define&&define); | ||
!function(n,t,e){function u(n){var s,t=this,e=(s=4022871197,function(n){n=String(n);for(var t=0;t<n.length;t++){var e=.02519603282416938*(s+=n.charCodeAt(t));e-=s=e>>>0,s=(e*=s)>>>0,s+=4294967296*(e-=s)}return 2.3283064365386963e-10*(s>>>0)});t.next=function(){var n=2091639*t.s0+2.3283064365386963e-10*t.c;return t.s0=t.s1,t.s1=t.s2,t.s2=n-(t.c=0|n)},t.c=1,t.s0=e(" "),t.s1=e(" "),t.s2=e(" "),t.s0-=e(n),t.s0<0&&(t.s0+=1),t.s1-=e(n),t.s1<0&&(t.s1+=1),t.s2-=e(n),t.s2<0&&(t.s2+=1),e=null}function o(n,t){return t.c=n.c,t.s0=n.s0,t.s1=n.s1,t.s2=n.s2,t}function s(n,t){var e=new u(n),s=t&&t.state,r=e.next;return r.int32=function(){return 4294967296*e.next()|0},r.double=function(){return r()+11102230246251565e-32*(2097152*r()|0)},r.quick=r,s&&("object"==typeof s&&o(s,e),r.state=function(){return o(e,{})}),r}t&&t.exports?t.exports=s:e&&e.amd?e(function(){return s}):this.alea=s}(0,"object"==typeof module&&module,"function"==typeof define&&define); |
{ | ||
"name": "seedrandom", | ||
"version": "2.4.4", | ||
"version": "3.0.0", | ||
"description": "Seeded random number generator for Javascript.", | ||
@@ -56,2 +55,3 @@ "main": "index.js", | ||
} | ||
} |
@@ -9,7 +9,7 @@ seedrandom.js | ||
Version 2.4.4 | ||
Version 3.0.0 | ||
Author: David Bau | ||
Date: 2018-08-14 | ||
Date: 2019-03-03 | ||
@@ -23,3 +23,3 @@ Can be used as a plain script, a Node.js module or an AMD module. | ||
```html | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.4.4/seedrandom.min.js"> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.0/seedrandom.min.js"> | ||
</script> | ||
@@ -29,29 +29,43 @@ ``` | ||
```js | ||
// Sets Math.random to a PRNG initialized using the given explicit seed. | ||
Math.seedrandom('hello.'); | ||
console.log(Math.random()); // Always 0.9282578795792454 | ||
console.log(Math.random()); // Always 0.3752569768646784 | ||
// Sets Math.random to an ARC4-based PRNG that is autoseeded using the | ||
// current time, dom state, and other accumulated local entropy. | ||
// The generated seed string is returned. | ||
Math.seedrandom(); | ||
console.log(Math.random()); // Reasonably unpredictable. | ||
// Seeds using the given explicit seed mixed with accumulated entropy. | ||
Math.seedrandom('added entropy.', { entropy: true }); | ||
console.log(Math.random()); // As unpredictable as added entropy. | ||
// Use "new" to create a local prng without altering Math.random. | ||
// Make a predictable pseudorandom number generator. | ||
var myrng = new Math.seedrandom('hello.'); | ||
console.log(myrng()); // Always 0.9282578795792454 | ||
console.log(myrng()); // Always 0.3752569768646784 | ||
// Use "quick" to get only 32 bits of randomness in a float. | ||
console.log(myrng.quick()); // Always 0.3752569768112153 | ||
console.log(myrng.quick()); // Always 0.7316977467853576 | ||
// Use "int32" to get a 32 bit (signed) integer | ||
console.log(myrng.int32()); // Always 986220731 | ||
console.log(myrng.int32()); // Always 1966374204 | ||
// Calling seedrandom with no arguments creates an ARC4-based PRNG | ||
// that is autoseeded using the current time, dom state, and other | ||
// accumulated local entropy. | ||
var prng = new Math.seedrandom(); | ||
console.log(prng()); // Reasonably unpredictable. | ||
// Seeds using the given explicit seed mixed with accumulated entropy. | ||
prng = new Math.seedrandom('added entropy.', { entropy: true }); | ||
console.log(prng()); // As unpredictable as added entropy. | ||
// Warning: if you call Math.seedrandom without `new`, it replaces | ||
// Math.random with the predictable new Math.seedrandom(...), as follows: | ||
Math.seedrandom('hello.'); | ||
console.log(Math.random()); // Always 0.9282578795792454 | ||
console.log(Math.random()); // Always 0.3752569768646784 | ||
``` | ||
**Note**: calling `Math.seedrandom('constant')` without `new` will make | ||
`Math.random()` predictable globally, which is intended to be useful for | ||
derandomizing code for testing, but should not be done in a production library. | ||
If you need a local seeded PRNG, use `myrng = new Math.seedrandom('seed')` | ||
instead. For example, [cryptico](https://www.npmjs.com/package/cryptico), | ||
an RSA encryption package, [uses the wrong form]( | ||
https://github.com/wwwtyro/cryptico/blob/9291ece6/api.js#L264), | ||
and thus secretly makes `Math.random()` perfectly predictable. | ||
The cryptico library (and any other library that does this) | ||
should not be trusted in a security-sensitive application. | ||
Other Fast PRNG Algorithms | ||
@@ -65,3 +79,3 @@ -------------------------- | ||
```html | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.4.4/lib/alea.min.js"> | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.0/lib/alea.min.js"> | ||
</script> | ||
@@ -104,4 +118,4 @@ ``` | ||
Node.js usage | ||
------------- | ||
CJS / Node.js usage | ||
------------------- | ||
@@ -135,3 +149,6 @@ ``` | ||
Starting in version 3.0.0, when using via require('seedrandom'), the global | ||
`Math.seedrandom` is no longer available. | ||
Require.js usage | ||
@@ -158,3 +175,3 @@ ---------------- | ||
```html | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.4.4/seedrandom.min.js> | ||
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.0/seedrandom.min.js> | ||
</script> | ||
@@ -252,2 +269,3 @@ <!-- Seeds using urandom bits from a server. --> | ||
* Version 2.4.4 avoids strict mode problem with global this reference. | ||
* Version 3.0.0 removes Math.seedrandom for require('seedrandom') users. | ||
@@ -254,0 +272,0 @@ The standard ARC4 key scheduler cycles short keys, which means that |
@@ -108,3 +108,2 @@ /* | ||
} | ||
math['seed' + rngname] = seedrandom; | ||
@@ -245,4 +244,8 @@ // | ||
define(function() { return seedrandom; }); | ||
} else { | ||
// When included as a plain script, set up Math.seedrandom global. | ||
math['seed' + rngname] = seedrandom; | ||
} | ||
// End anonymous scope, and pass initial values. | ||
@@ -249,0 +252,0 @@ })( |
@@ -1,1 +0,1 @@ | ||
!function(a,b){var l,c=eval("this"),d=256,g="random",h=b.pow(d,6),i=b.pow(2,52),j=2*i,k=d-1;function m(r,t,e){var u=[],f=q(function n(r,t){var e,o=[],i=typeof r;if(t&&"object"==i)for(e in r)try{o.push(n(r[e],t-1))}catch(n){}return o.length?o:"string"==i?r:r+"\0"}((t=1==t?{entropy:!0}:t||{}).entropy?[r,s(a)]:null==r?function(){try{var n;return l&&(n=l.randomBytes)?n=n(d):(n=new Uint8Array(d),(c.crypto||c.msCrypto).getRandomValues(n)),s(n)}catch(n){var r=c.navigator,t=r&&r.plugins;return[+new Date,c,t,c.screen,s(a)]}}():r,3),u),p=new n(u),m=function(){for(var n=p.g(6),r=h,t=0;n<i;)n=(n+t)*d,r*=d,t=p.g(1);for(;j<=n;)n/=2,r/=2,t>>>=1;return(n+t)/r};return m.int32=function(){return 0|p.g(4)},m.quick=function(){return p.g(4)/4294967296},m.double=m,q(s(p.S),a),(t.pass||e||function(n,r,t,e){return e&&(e.S&&o(e,p),n.state=function(){return o(p,{})}),t?(b[g]=n,r):n})(m,f,"global"in t?t.global:this==b,t.state)}function n(n){var r,t=n.length,u=this,e=0,o=u.i=u.j=0,i=u.S=[];for(t||(n=[t++]);e<d;)i[e]=e++;for(e=0;e<d;e++)i[e]=i[o=k&o+n[e%t]+(r=i[e])],i[o]=r;(u.g=function(n){for(var r,t=0,e=u.i,o=u.j,i=u.S;n--;)r=i[e=k&e+1],t=t*d+i[k&(i[e]=i[o=k&o+r])+(i[o]=r)];return u.i=e,u.j=o,t})(d)}function o(n,r){return r.i=n.i,r.j=n.j,r.S=n.S.slice(),r}function q(n,r){for(var t,e=n+"",o=0;o<e.length;)r[k&o]=k&(t^=19*r[k&o])+e.charCodeAt(o++);return s(r)}function s(n){return String.fromCharCode.apply(0,n)}if(b["seed"+g]=m,q(b.random(),a),"object"==typeof module&&module.exports){module.exports=m;try{l=require("crypto")}catch(n){}}else"function"==typeof define&&define.amd&&define(function(){return m})}([],Math); | ||
!function(a,b){var l,c=eval("this"),d=256,g="random",h=b.pow(d,6),i=b.pow(2,52),j=2*i,k=d-1;function m(r,t,e){var u=[],f=q(function n(r,t){var e,o=[],i=typeof r;if(t&&"object"==i)for(e in r)try{o.push(n(r[e],t-1))}catch(n){}return o.length?o:"string"==i?r:r+"\0"}((t=1==t?{entropy:!0}:t||{}).entropy?[r,s(a)]:null==r?function(){try{var n;return l&&(n=l.randomBytes)?n=n(d):(n=new Uint8Array(d),(c.crypto||c.msCrypto).getRandomValues(n)),s(n)}catch(n){var r=c.navigator,t=r&&r.plugins;return[+new Date,c,t,c.screen,s(a)]}}():r,3),u),p=new n(u),m=function(){for(var n=p.g(6),r=h,t=0;n<i;)n=(n+t)*d,r*=d,t=p.g(1);for(;j<=n;)n/=2,r/=2,t>>>=1;return(n+t)/r};return m.int32=function(){return 0|p.g(4)},m.quick=function(){return p.g(4)/4294967296},m.double=m,q(s(p.S),a),(t.pass||e||function(n,r,t,e){return e&&(e.S&&o(e,p),n.state=function(){return o(p,{})}),t?(b[g]=n,r):n})(m,f,"global"in t?t.global:this==b,t.state)}function n(n){var r,t=n.length,u=this,e=0,o=u.i=u.j=0,i=u.S=[];for(t||(n=[t++]);e<d;)i[e]=e++;for(e=0;e<d;e++)i[e]=i[o=k&o+n[e%t]+(r=i[e])],i[o]=r;(u.g=function(n){for(var r,t=0,e=u.i,o=u.j,i=u.S;n--;)r=i[e=k&e+1],t=t*d+i[k&(i[e]=i[o=k&o+r])+(i[o]=r)];return u.i=e,u.j=o,t})(d)}function o(n,r){return r.i=n.i,r.j=n.j,r.S=n.S.slice(),r}function q(n,r){for(var t,e=n+"",o=0;o<e.length;)r[k&o]=k&(t^=19*r[k&o])+e.charCodeAt(o++);return s(r)}function s(n){return String.fromCharCode.apply(0,n)}if(q(b.random(),a),"object"==typeof module&&module.exports){module.exports=m;try{l=require("crypto")}catch(n){}}else"function"==typeof define&&define.amd?define(function(){return m}):b["seed"+g]=m}([],Math); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
321
0
3
50600
24
966