Random Integers and Floats

suggest change
var a = Math.random();

Sample value of a: 0.21322848065742162

Math.random() returns a random number between 0 (inclusive) and 1 (exclusive)

function getRandom() {
    return Math.random();
}

To use Math.random() to get a number from an arbitrary range (not [0,1)) use this function to get a random number between min (inclusive) and max (exclusive): interval of [min, max)

function getRandomArbitrary(min, max) {
  return Math.random() * (max - min) + min;
}

To use Math.random() to get an integer from an arbitrary range (not [0,1)) use this function to get a random number between min (inclusive) and max (exclusive): interval of [min, max)

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}

To use Math.random() to get an integer from an arbitrary range (not [0,1)) use this function to get a random number between min (inclusive) and max (inclusive): interval of [min, max]

function getRandomIntInclusive(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

Functions taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Arithmetic Math:
* Random Integers and Floats

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
18 Arithmetic Math
24 Loops
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde