root / trunk / web / dojo / dojox / math / random / prng4.js
History | View | Annotate | Download (857 Bytes)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
| 3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
| 4 | see: http://dojotoolkit.org/license for details
|
||
| 5 | */
|
||
| 6 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dojox.math.random.prng4"]){ |
||
| 9 | dojo._hasResource["dojox.math.random.prng4"]=true; |
||
| 10 | dojo.provide("dojox.math.random.prng4");
|
||
| 11 | (function(){
|
||
| 12 | function _1(){ |
||
| 13 | this.i=0; |
||
| 14 | this.j=0; |
||
| 15 | this.S=new Array(256); |
||
| 16 | }; |
||
| 17 | dojo.extend(_1,{init:function(_2){
|
||
| 18 | var i,j,t,S=this.S,_3=_2.length; |
||
| 19 | for(i=0;i<256;++i){ |
||
| 20 | S[i]=i; |
||
| 21 | } |
||
| 22 | j=0;
|
||
| 23 | for(i=0;i<256;++i){ |
||
| 24 | j=(j+S[i]+_2[i%_3])&255;
|
||
| 25 | t=S[i]; |
||
| 26 | S[i]=S[j]; |
||
| 27 | S[j]=t; |
||
| 28 | } |
||
| 29 | this.i=0; |
||
| 30 | this.j=0; |
||
| 31 | },next:function(){ |
||
| 32 | var t,i,j,S=this.S; |
||
| 33 | this.i=i=(this.i+1)&255; |
||
| 34 | this.j=j=(this.j+S[i])&255; |
||
| 35 | t=S[i]; |
||
| 36 | S[i]=S[j]; |
||
| 37 | S[j]=t; |
||
| 38 | return S[(t+S[i])&255]; |
||
| 39 | }}); |
||
| 40 | dojox.math.random.prng4=function(){ |
||
| 41 | return new _1(); |
||
| 42 | }; |
||
| 43 | dojox.math.random.prng4.size=256;
|
||
| 44 | })(); |
||
| 45 | } |