summaryrefslogtreecommitdiff
path: root/js/dojo-1.6/dojox/math/random
diff options
context:
space:
mode:
Diffstat (limited to 'js/dojo-1.6/dojox/math/random')
-rw-r--r--js/dojo-1.6/dojox/math/random/Secure.js107
-rw-r--r--js/dojo-1.6/dojox/math/random/Secure.xd.js111
-rw-r--r--js/dojo-1.6/dojox/math/random/Simple.js36
-rw-r--r--js/dojo-1.6/dojox/math/random/Simple.xd.js40
-rw-r--r--js/dojo-1.6/dojox/math/random/prng4.js69
-rw-r--r--js/dojo-1.6/dojox/math/random/prng4.xd.js73
6 files changed, 436 insertions, 0 deletions
diff --git a/js/dojo-1.6/dojox/math/random/Secure.js b/js/dojo-1.6/dojox/math/random/Secure.js
new file mode 100644
index 0000000..fe87a32
--- /dev/null
+++ b/js/dojo-1.6/dojox/math/random/Secure.js
@@ -0,0 +1,107 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.math.random.Secure"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.math.random.Secure"] = true;
+dojo.provide("dojox.math.random.Secure");
+
+
+
+// Copyright (c) 2005 Tom Wu
+// All Rights Reserved.
+// See "LICENSE-BigInteger" for details.
+
+// Random number generator - requires a PRNG backend, e.g. prng4.js
+
+dojo.declare("dojox.math.random.Secure", null, {
+ // summary:
+ // Super simple implementation of a random number generator,
+ // which relies on Math.random().
+
+ constructor: function(prng, noEvents){
+ // summary:
+ // Intializes an instance of a secure random generator.
+ // prng: Function:
+ // function that returns an instance of PRNG (pseudorandom number generator)
+ // with two methods: init(array) and next(). It should have a property "size"
+ // to indicate the required pool size.
+ // noEvents: Boolean?:
+ // if false or absent, onclick and onkeypress event will be used to add
+ // "randomness", otherwise events will not be used.
+ this.prng = prng;
+
+ // Initialize the pool with junk if needed.
+ var p = this.pool = new Array(prng.size);
+ this.pptr = 0;
+ for(var i = 0, len = prng.size; i < len;) { // extract some randomness from Math.random()
+ var t = Math.floor(65536 * Math.random());
+ p[i++] = t >>> 8;
+ p[i++] = t & 255;
+ }
+ this.seedTime();
+
+ if(!noEvents){
+ this.h = [
+ dojo.connect(dojo.body(), "onclick", this, "seedTime"),
+ dojo.connect(dojo.body(), "onkeypress", this, "seedTime")
+ ];
+ }
+ },
+
+ destroy: function(){
+ // summary:
+ // Disconnects events, if any, preparing the object for GC.
+ if(this.h){
+ dojo.forEach(this.h, dojo.disconnect);
+ }
+ },
+
+ nextBytes: function(/* Array */ byteArray){
+ // summary:
+ // Fills in an array of bytes with random numbers
+ // byteArray: Array:
+ // array to be filled in with random numbers, only existing
+ // elements will be filled.
+
+ var state = this.state;
+
+ if(!state){
+ this.seedTime();
+ state = this.state = this.prng();
+ state.init(this.pool);
+ for(var p = this.pool, i = 0, len = p.length; i < len; p[i++] = 0);
+ this.pptr = 0;
+ //this.pool = null;
+ }
+
+ for(var i = 0, len = byteArray.length; i < len; ++i){
+ byteArray[i] = state.next();
+ }
+ },
+
+ seedTime: function() {
+ // summary:
+ // Mix in the current time (w/milliseconds) into the pool
+ this._seed_int(new Date().getTime());
+ },
+
+ _seed_int: function(x) {
+ // summary:
+ // Mix in a 32-bit integer into the pool
+ var p = this.pool, i = this.pptr;
+ p[i++] ^= x & 255;
+ p[i++] ^= (x >> 8) & 255;
+ p[i++] ^= (x >> 16) & 255;
+ p[i++] ^= (x >> 24) & 255;
+ if(i >= this.prng.size){
+ i -= this.prng.size;
+ }
+ this.pptr = i;
+ }
+});
+
+}
diff --git a/js/dojo-1.6/dojox/math/random/Secure.xd.js b/js/dojo-1.6/dojox/math/random/Secure.xd.js
new file mode 100644
index 0000000..659390c
--- /dev/null
+++ b/js/dojo-1.6/dojox/math/random/Secure.xd.js
@@ -0,0 +1,111 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.math.random.Secure"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.math.random.Secure"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.math.random.Secure"] = true;
+dojo.provide("dojox.math.random.Secure");
+
+
+
+// Copyright (c) 2005 Tom Wu
+// All Rights Reserved.
+// See "LICENSE-BigInteger" for details.
+
+// Random number generator - requires a PRNG backend, e.g. prng4.js
+
+dojo.declare("dojox.math.random.Secure", null, {
+ // summary:
+ // Super simple implementation of a random number generator,
+ // which relies on Math.random().
+
+ constructor: function(prng, noEvents){
+ // summary:
+ // Intializes an instance of a secure random generator.
+ // prng: Function:
+ // function that returns an instance of PRNG (pseudorandom number generator)
+ // with two methods: init(array) and next(). It should have a property "size"
+ // to indicate the required pool size.
+ // noEvents: Boolean?:
+ // if false or absent, onclick and onkeypress event will be used to add
+ // "randomness", otherwise events will not be used.
+ this.prng = prng;
+
+ // Initialize the pool with junk if needed.
+ var p = this.pool = new Array(prng.size);
+ this.pptr = 0;
+ for(var i = 0, len = prng.size; i < len;) { // extract some randomness from Math.random()
+ var t = Math.floor(65536 * Math.random());
+ p[i++] = t >>> 8;
+ p[i++] = t & 255;
+ }
+ this.seedTime();
+
+ if(!noEvents){
+ this.h = [
+ dojo.connect(dojo.body(), "onclick", this, "seedTime"),
+ dojo.connect(dojo.body(), "onkeypress", this, "seedTime")
+ ];
+ }
+ },
+
+ destroy: function(){
+ // summary:
+ // Disconnects events, if any, preparing the object for GC.
+ if(this.h){
+ dojo.forEach(this.h, dojo.disconnect);
+ }
+ },
+
+ nextBytes: function(/* Array */ byteArray){
+ // summary:
+ // Fills in an array of bytes with random numbers
+ // byteArray: Array:
+ // array to be filled in with random numbers, only existing
+ // elements will be filled.
+
+ var state = this.state;
+
+ if(!state){
+ this.seedTime();
+ state = this.state = this.prng();
+ state.init(this.pool);
+ for(var p = this.pool, i = 0, len = p.length; i < len; p[i++] = 0);
+ this.pptr = 0;
+ //this.pool = null;
+ }
+
+ for(var i = 0, len = byteArray.length; i < len; ++i){
+ byteArray[i] = state.next();
+ }
+ },
+
+ seedTime: function() {
+ // summary:
+ // Mix in the current time (w/milliseconds) into the pool
+ this._seed_int(new Date().getTime());
+ },
+
+ _seed_int: function(x) {
+ // summary:
+ // Mix in a 32-bit integer into the pool
+ var p = this.pool, i = this.pptr;
+ p[i++] ^= x & 255;
+ p[i++] ^= (x >> 8) & 255;
+ p[i++] ^= (x >> 16) & 255;
+ p[i++] ^= (x >> 24) & 255;
+ if(i >= this.prng.size){
+ i -= this.prng.size;
+ }
+ this.pptr = i;
+ }
+});
+
+}
+
+}};});
diff --git a/js/dojo-1.6/dojox/math/random/Simple.js b/js/dojo-1.6/dojox/math/random/Simple.js
new file mode 100644
index 0000000..f57c8bf
--- /dev/null
+++ b/js/dojo-1.6/dojox/math/random/Simple.js
@@ -0,0 +1,36 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.math.random.Simple"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.math.random.Simple"] = true;
+dojo.provide("dojox.math.random.Simple");
+
+
+
+dojo.declare("dojox.math.random.Simple", null, {
+ // summary:
+ // Super simple implementation of a random number generator,
+ // which relies on Math.random().
+
+ destroy: function(){
+ // summary:
+ // Prepares the object for GC. (empty in this case)
+ },
+
+ nextBytes: function(/* Array */ byteArray){
+ // summary:
+ // Fills in an array of bytes with random numbers
+ // byteArray: Array:
+ // array to be filled in with random numbers, only existing
+ // elements will be filled.
+ for(var i = 0, l = byteArray.length; i < l; ++i){
+ byteArray[i] = Math.floor(256 * Math.random());
+ }
+ }
+});
+
+}
diff --git a/js/dojo-1.6/dojox/math/random/Simple.xd.js b/js/dojo-1.6/dojox/math/random/Simple.xd.js
new file mode 100644
index 0000000..53e4283
--- /dev/null
+++ b/js/dojo-1.6/dojox/math/random/Simple.xd.js
@@ -0,0 +1,40 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.math.random.Simple"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.math.random.Simple"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.math.random.Simple"] = true;
+dojo.provide("dojox.math.random.Simple");
+
+
+
+dojo.declare("dojox.math.random.Simple", null, {
+ // summary:
+ // Super simple implementation of a random number generator,
+ // which relies on Math.random().
+
+ destroy: function(){
+ // summary:
+ // Prepares the object for GC. (empty in this case)
+ },
+
+ nextBytes: function(/* Array */ byteArray){
+ // summary:
+ // Fills in an array of bytes with random numbers
+ // byteArray: Array:
+ // array to be filled in with random numbers, only existing
+ // elements will be filled.
+ for(var i = 0, l = byteArray.length; i < l; ++i){
+ byteArray[i] = Math.floor(256 * Math.random());
+ }
+ }
+});
+
+}
+
+}};});
diff --git a/js/dojo-1.6/dojox/math/random/prng4.js b/js/dojo-1.6/dojox/math/random/prng4.js
new file mode 100644
index 0000000..c180368
--- /dev/null
+++ b/js/dojo-1.6/dojox/math/random/prng4.js
@@ -0,0 +1,69 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.math.random.prng4"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.math.random.prng4"] = true;
+dojo.provide("dojox.math.random.prng4");
+
+
+dojo.getObject("math.random.prng4", true, dojox);
+
+// Copyright (c) 2005 Tom Wu
+// All Rights Reserved.
+// See "LICENSE-BigInteger" for details.
+
+(function(){
+ // prng4.js - uses Arcfour as a PRNG
+
+ function Arcfour() {
+ this.i = 0;
+ this.j = 0;
+ this.S = new Array(256);
+ }
+
+ dojo.extend(Arcfour, {
+ init: function(key){
+ // summary:
+ // Initialize arcfour context
+ // key: Array:
+ // an array of ints, each from [0..255]
+ var i, j, t, S = this.S, len = key.length;
+ for(i = 0; i < 256; ++i){
+ S[i] = i;
+ }
+ j = 0;
+ for(i = 0; i < 256; ++i){
+ j = (j + S[i] + key[i % len]) & 255;
+ t = S[i];
+ S[i] = S[j];
+ S[j] = t;
+ }
+ this.i = 0;
+ this.j = 0;
+ },
+
+ next: function(){
+ var t, i, j, S = this.S;
+ this.i = i = (this.i + 1) & 255;
+ this.j = j = (this.j + S[i]) & 255;
+ t = S[i];
+ S[i] = S[j];
+ S[j] = t;
+ return S[(t + S[i]) & 255];
+ }
+ });
+
+ dojox.math.random.prng4 = function(){
+ return new Arcfour();
+ };
+
+ // Pool size must be a multiple of 4 and greater than 32.
+ // An array of bytes the size of the pool will be passed to init()
+ dojox.math.random.prng4.size = 256;
+})();
+
+}
diff --git a/js/dojo-1.6/dojox/math/random/prng4.xd.js b/js/dojo-1.6/dojox/math/random/prng4.xd.js
new file mode 100644
index 0000000..dac3455
--- /dev/null
+++ b/js/dojo-1.6/dojox/math/random/prng4.xd.js
@@ -0,0 +1,73 @@
+/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {depends: [["provide", "dojox.math.random.prng4"]],
+defineResource: function(dojo, dijit, dojox){if(!dojo._hasResource["dojox.math.random.prng4"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.math.random.prng4"] = true;
+dojo.provide("dojox.math.random.prng4");
+
+
+dojo.getObject("math.random.prng4", true, dojox);
+
+// Copyright (c) 2005 Tom Wu
+// All Rights Reserved.
+// See "LICENSE-BigInteger" for details.
+
+(function(){
+ // prng4.js - uses Arcfour as a PRNG
+
+ function Arcfour() {
+ this.i = 0;
+ this.j = 0;
+ this.S = new Array(256);
+ }
+
+ dojo.extend(Arcfour, {
+ init: function(key){
+ // summary:
+ // Initialize arcfour context
+ // key: Array:
+ // an array of ints, each from [0..255]
+ var i, j, t, S = this.S, len = key.length;
+ for(i = 0; i < 256; ++i){
+ S[i] = i;
+ }
+ j = 0;
+ for(i = 0; i < 256; ++i){
+ j = (j + S[i] + key[i % len]) & 255;
+ t = S[i];
+ S[i] = S[j];
+ S[j] = t;
+ }
+ this.i = 0;
+ this.j = 0;
+ },
+
+ next: function(){
+ var t, i, j, S = this.S;
+ this.i = i = (this.i + 1) & 255;
+ this.j = j = (this.j + S[i]) & 255;
+ t = S[i];
+ S[i] = S[j];
+ S[j] = t;
+ return S[(t + S[i]) & 255];
+ }
+ });
+
+ dojox.math.random.prng4 = function(){
+ return new Arcfour();
+ };
+
+ // Pool size must be a multiple of 4 and greater than 32.
+ // An array of bytes the size of the pool will be passed to init()
+ dojox.math.random.prng4.size = 256;
+})();
+
+}
+
+}};});