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.

40,026 questions

51,982 answers

573 users

How to generating random numbers in a specific range in Javascript

2 Answers

0 votes
var i;

// 20 numbers between: 1 - 10

for (i = 1; i < 20; i++)
    document.write((Math.floor(Math.random() * (10 - 1 + 1)) + 1) + "<br />");    
            
/*
run:
  
1
7
3
4
5
6
5
1
1
4
9
2
1
4
8
7
1
7
8
  
*/

 



answered Jul 16, 2015 by avibootz
0 votes
var i;

// 30 numbers between: 1 - 100

var max = 100
var min = 1;

for (i = 1; i < 30; i++)
    document.write((Math.floor(Math.random() * (max - min + 1)) + min) + "<br />");    
            
/*
run:
  
25
92
77
29
100
60
60
33
40
20
84
58
35
22
47
45
44
99
1
81
75
82
10
67
24
86
49
76
69
  
*/

 



answered Jul 16, 2015 by avibootz
...