@@ -2,7 +2,7 @@ function rand( min, max ) {
22 // http://kevin.vanzonneveld.net
33 // + original by: Leslie Hoare
44 // + bugfixed by: Onno Marsman
5- // % note 1: See the commented out code below for a version which will work with our experimental (though probably unnecessary) srand() function)
5+ // % note 1: See the commented out code below for a version which will work with our experimental (though probably unnecessary) srand() function)
66 // * example 1: rand(1, 1);
77 // * returns 1: 1
88
@@ -18,35 +18,35 @@ function rand( min, max ) {
1818 /*
1919 // See note above for an explanation of the following alternative code
2020
21- // + reimplemented by: Brett Zamir (http://brettz9.blogspot.com)
22- // - depends on: srand
23- // % note 1: This is a very possibly imperfect adaptation from the PHP source code
24- var rand_seed, ctx, PHP_RAND_MAX=2147483647; // 0x7fffffff
21+ // + reimplemented by: Brett Zamir (http://brettz9.blogspot.com)
22+ // - depends on: srand
23+ // % note 1: This is a very possibly imperfect adaptation from the PHP source code
24+ var rand_seed, ctx, PHP_RAND_MAX=2147483647; // 0x7fffffff
2525
26- if (!this.php_js || this.php_js.rand_seed === undefined) {
27- this.srand();
28- }
29- rand_seed = this.php_js.rand_seed;
26+ if (!this.php_js || this.php_js.rand_seed === undefined) {
27+ this.srand();
28+ }
29+ rand_seed = this.php_js.rand_seed;
3030
31- var argc = arguments.length;
31+ var argc = arguments.length;
3232 if (argc === 1) {
3333 throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
3434 }
3535
36- var do_rand = function (ctx) {
37- return ((ctx * 1103515245 + 12345) % (PHP_RAND_MAX + 1));
38- };
36+ var do_rand = function (ctx) {
37+ return ((ctx * 1103515245 + 12345) % (PHP_RAND_MAX + 1));
38+ };
3939
40- var php_rand = function (ctxArg) { // php_rand_r
41- this.php_js.rand_seed = do_rand(ctxArg);
42- return parseInt(this.php_js.rand_seed, 10);
43- };
40+ var php_rand = function (ctxArg) { // php_rand_r
41+ this.php_js.rand_seed = do_rand(ctxArg);
42+ return parseInt(this.php_js.rand_seed, 10);
43+ };
4444
45- var number = php_rand(rand_seed);
45+ var number = php_rand(rand_seed);
4646
47- if (argc === 2) {
48- number = min + parseInt(parseFloat(parseFloat(max) - min + 1.0) * (number/(PHP_RAND_MAX + 1.0)), 10);
47+ if (argc === 2) {
48+ number = min + parseInt(parseFloat(parseFloat(max) - min + 1.0) * (number/(PHP_RAND_MAX + 1.0)), 10);
4949 }
50- return number;
50+ return number;
5151 */
5252}
0 commit comments