Random example of random function of JS generating random number

Source: Internet
Author: User
Tags current time

JS generate random number can use JavaScript math.random () built-in functions, here is a good example, you can try to operate under

The JavaScript math.random () built-in function random return value returns a pseudo random number between 0 and 1, possibly 0, but always less than 1,[0,1) random function Example//returns the random number document.write (Math.rando  m ());  Returns a random number of 10-20 document.write (Math.random () * (20-10) +10);  Returns the formula for the specified range of random numbers (m-n) document.write (Math.random () * (N-M) +m);  Based on time, also can generate random number code as follows: Var now=new Date (); var number = Now.getseconds ();  This will result in a 0 to 59 integer based on the current time.  var now=new Date (); var number = Now.getseconds ()%43; This will result in a 0 to 42 integer based on the current time.

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.