How to generate random number between 1 and 100 in Node.js

2 Answers

0 votes
const n = Math.floor((Math.random() * 100) + 1); 
  
console.log(n);
 
 
 
   
/*
run:
  
74
   
*/

 



answered May 25, 2022 by avibootz
0 votes
for (let i = 0; i < 20; i++) {
    let n = Math.floor((Math.random() * 100) + 1); 
    console.log(n);
}
  
  
  
/*
run:
 
24
46
63
100
68
29
83
40
30
82
69
55
31
35
16
100
6
5
79
65
  
*/

 



answered May 25, 2022 by avibootz

Related questions

2 answers 162 views
1 answer 104 views
1 answer 178 views
1 answer 97 views
2 answers 168 views
...