Since the creation of web effects, many browsers have built-in random number generation method. For example: var number =math.random ();
This method produces a floating-point number between 0 and 1.
Rnd.today=new date ();
Rnd.seed=rnd.today.gettime ();
function rnd () {
Rnd.seed = (rnd.seed*9301+49297)% 233280;
Return rnd.seed/(233280.0);
};
function rand (number) {
Return Math.ceil (Rnd () *number);
};
Let's look at a randomly generated lottery function
function Stringresource (k) {return stringresource[k] | | k;} function Randomselector () { var f = 0, c = [];
return function (V, r) { if (arguments.length) { if (r <= 0) throw {message:stringresource ("invalid_argument")}; C.push ([R, v]); F + + R; else { var i = 0; R = Math.random () * f; for (;;) if ((R-= (v = c[i++]) [0]) < 0) return v[1]; } }; }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.