1//To genereate a number between 0-1
2Math.random();
3//To generate a number that is a whole number rounded down
4Math.floor(Math.random())
5/*To generate a number that is a whole number rounded down between
61 and 10 */
7Math.floor(Math.random() * 10) + 1 //the + 1 makes it so its not 0.
1function randomNumber(min, max) {
2 return Math.floor(Math.random() * (max - min)) + min;
3}
1Math.floor(Math.random() * (max - min + 1)) + min;
2
3// Between 0 and max
4Math.floor(Math.random() * (max + 1));
5
6// Between 1 and max
7Math.floor(Math.random() * max) + 1;
1function getRandomArbitrary(min, max) {
2 return Math.random() * (max - min) + min;
3}
4
1var randomnumber = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum;
2
1/**
2 * Returns a random number between min (inclusive) and max (exclusive)
3 */
4function getRandomArbitrary(min, max) {
5 return Math.random() * (max - min) + min;
6}
7
8/**
9 * Returns a random integer between min (inclusive) and max (inclusive).
10 * The value is no lower than min (or the next integer greater than min
11 * if min isn't an integer) and no greater than max (or the next integer
12 * lower than max if max isn't an integer).
13 * Using Math.round() will give you a non-uniform distribution!
14 */
15function getRandomInt(min, max) {
16 min = Math.ceil(min);
17 max = Math.floor(max);
18 return Math.floor(Math.random() * (max - min + 1)) + min;
19}
20