10 examples of 'choose a random number between 1 and 100' in JavaScript

Every line of 'choose a random number between 1 and 100' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
8function randomNumber(min, max) {
9 return Math.floor(Math.random() * (max - min + 1)) + min;
10}
2function randomNumber(max, min) {
3 return Math.floor(Math.random() * (max - min + 1) + min);
4}
82function randomNumber(min, max) {
83 return Math.random() * (max - min) + min;
84}
4function randomNumber(min, max) {
5 return Math.random() * (max - min) + min;
6}
37function randomNumber(max){
38 /* Return a random number
39 max: highest random number (default is 100).
40 */
41 max = typeof max !== 'undefined' ? max : 100;
42 return Random.randInt(max);
43};
159function getRandom(min,max){
160 //Math.random()*(上限-下限+1)+下限
161 return parseInt(Math.random() * (max - min + 1) + min);
162}
828function getRandom(min, max) {
829 var int = Math.random() * (max - min) + min;
830 int = parseInt(int);
831 return int;
832}
31number(min, max) {
32 const number = this.generate()
33 return Math.round((max - min) * number + min)
34}
31function random(min, max) {
32 if (arguments.length < 2) {
33 max = min;
34 min = 0;
35 }
36
37 if (min > max) {
38 var hold = max;
39 max = min;
40 min = hold;
41 }
42
43 return Math.floor(Math.random() * (max - min + 1)) + min;
44}
13export function random (max) {
14 return seeded.integerInRange(0, max)
15}

Related snippets