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.
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.