-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathJS_random
More file actions
23 lines (14 loc) · 723 Bytes
/
JS_random
File metadata and controls
23 lines (14 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#JavaScript Random Integers
Math.floor(Math.random() * 10); // returns a random integer from 0 to 9
Math.floor(Math.random() * 11); // returns a random integer from 0 to 10
Math.floor(Math.random() * 100); // returns a random integer from 0 to 99
Math.floor(Math.random() * 101); // returns a random integer from 0 to 100
Math.floor(Math.random() * 10) + 1; // returns a random integer from 1 to 10
Math.floor(Math.random() * 100) + 1; // returns a random integer from 1 to 100
#A Proper Random Function
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min) ) + min;
}
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}