Last active
December 15, 2015 17:18
-
-
Save debjitbis08/5295038 to your computer and use it in GitHub Desktop.
Revisions
-
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,7 +56,7 @@ }; /* Usage */ var a = Array(1009), i = 0, seed = Date ? +new Date() : 310952; ranf_start(seed); ranf_array(a,1009); window.random = function () { -
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ var ranf_start = function (seed) { var t,s,j; var u = Array(KK+KK-1); var ulp=(1.0/(1<<30))/(1<<22); /* 2 to the -52 */ var ss=2.0*ulp*((seed&0x3fffffff)+2); var TT = 70; /* guaranteed separation between streams */ -
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -60,8 +60,7 @@ ranf_start(seed); ranf_array(a,1009); window.random = function () { 1009 === i && (seed = a[i-1], i = 0, ranf_start(seed), ranf_array(a, 1009)); return a[i++]; }; })(); -
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -61,6 +61,7 @@ ranf_array(a,1009); window.random = function () { 1009 === i && (seed = a[i-1], ranf_start(seed), ranf_array(a, 1009)); i = 0; return a[i++]; }; })(); -
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -45,7 +45,7 @@ } if (is_odd(s)) { /* "multiply by z" */ for (j=KK;j>0;j--) u[j]=u[j-1]; u[0]=u[KK]; /* shift the buffer cyclically */ u[LL]=mod_sum(u[LL],u[KK]); } if (s) s>>=1; else t--; @@ -56,11 +56,11 @@ }; /* Usage */ var a = Array(1009), i = 0, seed = 310952; ranf_start(seed); ranf_array(a,1009); window.random = function () { 1009 === i && (seed = a[i-1], ranf_start(seed), ranf_array(a, 1009)); return a[i++]; }; })(); -
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ (function () { var KK = 100; var LL = 37; -
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ (function () { "use strict"; var KK = 100; var LL = 37; @@ -60,10 +62,7 @@ ranf_start(310952); ranf_array(a,1009); window.random = function () { 1009 === i && (ranf_start(310952), ranf_array(a, 1009)); return a[i++]; }; })(); -
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ (function () { var KK = 100; var LL = 37; -
Debjit Biswas revised this gist
Apr 3, 2013 . 1 changed file with 19 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,17 +5,21 @@ var LL = 37; var mod_sum = function (x, y) { return x+y-(x+y|0); }; var ran_u = Array(KK); var ranf_array = function (aa, n) { var i,j; for (j=0;j<KK;j++) aa[j]=ran_u[j]; for (;j<n;j++) aa[j] = aa[j-KK] + aa[j-LL] - (aa[j-KK] + aa[j-LL] | 0); for (i=0;i<LL;i++,j++) ran_u[i] = aa[j-KK] + aa[j-LL] - (aa[j-KK] + aa[j-LL] | 0); for (;i<KK;i++,j++) ran_u[i] = aa[j-KK] + ran_u[i-LL] - (aa[j-KK] + ran_u[i-LL] | 0); }; var ranf_start = function (seed) { @@ -26,7 +30,7 @@ var TT = 70; /* guaranteed separation between streams */ function is_odd (s) { return ((s)&1); } for (j=0;j<KK;j++) { @@ -54,7 +58,14 @@ }; /* Usage */ var a = Array(1009), i = 0; ranf_start(310952); ranf_array(a,1009); window.random = function () { if (i === 1009) { ranf_start(310952); ranf_array(a,1009); } return a[i++]; }; })(); -
Debjit Biswas created this gist
Apr 2, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ (function () { "use strict"; var KK = 100; var LL = 37; var mod_sum = function (x, y) { return (((x)+(y))-Math.floor(((x)+(y)))) }; var ran_u = []; var ranf_array = function (aa, n) { var i,j; for (j=0;j<KK;j++) aa[j]=ran_u[j]; for (;j<n;j++) aa[j]=mod_sum(aa[j-KK],aa[j-LL]); for (i=0;i<LL;i++,j++) ran_u[i]=mod_sum(aa[j-KK],aa[j-LL]); for (;i<KK;i++,j++) ran_u[i]=mod_sum(aa[j-KK],ran_u[i-LL]); }; var ranf_start = function (seed) { var t,s,j; var u = []; var ulp=(1.0/(1<<30))/(1<<22); /* 2 to the -52 */ var ss=2.0*ulp*((seed&0x3fffffff)+2); var TT = 70; /* guaranteed separation between streams */ function is_odd (s) { return ((s)&1) } for (j=0;j<KK;j++) { u[j]=ss; /* bootstrap the buffer */ ss+=ss; if (ss>=1.0) ss-=1.0-2*ulp; /* cyclic shift of 51 bits */ } u[1]+=ulp; /* make u[1] (and only u[1]) "odd" */ for (s=seed&0x3fffffff,t=TT-1; t; ) { for (j=KK-1;j>0;j--) u[j+j]=u[j],u[j+j-1]=0.0; /* "square" */ for (j=KK+KK-2;j>=KK;j--) { u[j-(KK-LL)]=mod_sum(u[j-(KK-LL)],u[j]); u[j-KK]=mod_sum(u[j-KK],u[j]); } if (is_odd(s)) { /* "multiply by z" */ for (j=KK;j>0;j--) u[j]=u[j-1]; u[0]=u[KK]; /* shift the buffer cyclically */ u[LL]=mod_sum(u[LL],u[KK]); } if (s) s>>=1; else t--; } for (j=0;j<LL;j++) ran_u[j+KK-LL]=u[j]; for (;j<KK;j++) ran_u[j-LL]=u[j]; for (j=0;j<10;j++) ranf_array(u,KK+KK-1); /* warm things up */ }; /* Usage */ var a = []; ranf_start(310952); ranf_array(a,1009); })();