Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to use Math.random() and Math.floor() to get a random number between min (included) and max (excluded) in JavaScript

2 Answers

0 votes
var min = 31;
var max  = 35;
var n;
n = Math.floor(Math.random() * (max - min)) + min;
document.write(n + "<br />");

 
/*
run

33
 
*/

 



answered Aug 5, 2016 by avibootz
0 votes
var min = 31;
var max  = 35;
var n;

for (var i = 0; i < 10; i++)
{
    n = Math.floor(Math.random() * (max - min)) + min;
    document.write(n + "<br />");
}

 
/*
run

31
32
33
31
31
31
33
34
34
34
 
*/

 



answered Aug 5, 2016 by avibootz
...