JS Math random Number

Source: Internet
Author: User

#2015-8-12

# #Math随机数


###**1**. JS random number (Don't ask me why, Baidu also don't know, Baidu latest version)

var rand
= (function () {
var today
= new Date ();
var seed
= Today.gettime ();
function rnd () {
Seed
= (Seed * 9301 + 49297)% 233280;
Return seed
/(233280.0);
};
return function rand (number) {
Return Math.ceil (Rnd (Seed)
* number);
};
})();

Console.log (rand (100))
Console.log (rand (100))
Console.log (rand (100))

# # #2. JS Math generates random numbers

function ext (min, max) {
Return Math.floor (min + math.random () * (max-min));
(Var random=ext (number of 1-n))//Here's ext for the above defined method
# # #3. JS link the final style sheet; Use this later (the code word is too long, do not know the meaning)

Alert (Document.defaultView.getComputedStyle (ev,null). BackgroundColor)

# # #4. The canvas gets the ID of the HTML and mixes the 2d parameters (Canvas essentials)

Canvas = document.getElementById ("CANVAS1")//Get ID Object
CXT = Canvas.getcontext (' 2d ')//adding 2d Parameters





JS Math random Number

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.