How to generate random number between 1 and 100 in TypeScript

2 Answers

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



  
/*
run:
 
89
  
*/

 



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:
 
79 
61 
11 
69 
87 
68 
78 
45 
75 
55 
22 
61 
61 
99 
25 
98 
88 
20 
100 
3 
  
*/

 



answered May 25, 2022 by avibootz

Related questions

1 answer 165 views
1 answer 145 views
1 answer 258 views
1 answer 155 views
2 answers 169 views
2 answers 276 views
...