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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,051 questions

40,769 answers

573 users

How to generate random number in Node.js

4 Answers

0 votes
let i = 0;
     
while (i < 20) {
    let number =  Math.floor(Math.random() * (8)); // 0 - 7
    console.log(number);
    i++;
}
 
 
 
 
/*
run:
 
1
6
0
6
4
4
3
4
6
7
7
2
5
3
5
3
5
7
4
7
 
*/

 





answered Oct 14, 2021 by avibootz
edited May 24, 2022 by avibootz
0 votes
for (let i = 0; i < 20; i++)
    console.log(Math.floor(Math.random() * 10));  // 0 - 9
 
 
 
 
/*
run:
 
4
8
9
4
7
7
3
6
6
1
1
0
3
1
3
4
8
1
9
9
 
*/

 





answered May 24, 2022 by avibootz
0 votes
const n = Math.random();
  
console.log(n);
   
   
   
   
   
/*
run:
  
0.15304185934544656
   
*/

 





answered May 24, 2022 by avibootz
0 votes
const n = Math.random() * 10;
  
console.log(n);
   
   
   
   
   
/*
run:
  
4.003934410536152
   
*/

 





answered May 24, 2022 by avibootz

Related questions

1 answer 30 views
2 answers 47 views
2 answers 62 views
1 answer 47 views
1 answer 60 views
...