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() to get a random number between min (inclusive) and max (exclusive) in JavaScript

2 Answers

0 votes
var min = 3;
var max  = 10;
var n = Math.random() * (max - min) + min;
document.write(n);

 
/*
run

9.120583119015542 
 
*/

 



answered Aug 5, 2016 by avibootz
0 votes
var min = 3;
var max  = 7;
var n;
for (var i = 0; i < 10; i++)
{
    n = Math.random() * (max - min) + min;
    document.write(n + "<br />");
}

 
/*
run

6.722737321850531
6.606430163025816
3.6566545749621513
4.694706528529381
4.129002148897234
3.974074155325747
4.659713472139972
4.019526055364357
3.975174493700944
4.255990438724478
 
*/

 



answered Aug 5, 2016 by avibootz
...