Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Math.random() returns a decimal between 0 (inclusive) and 1 (exclusive). Use it to generate random integers, pick random items, shuffle arrays, and more!
Returns decimal between 0 and 1
Generate random whole numbers
Generate random decimals between min and max
Select random element
Randomize array order (Fisher-Yates algorithm)
True or false with optional probability
Generate random hex colors
Generate random strings for IDs or tokens
Math.floor(Math.random() * (n + 1))Random integer from 0 to n (inclusive)
Math.floor(Math.random() * (max - min + 1)) + minRandom integer between min and max
Math.random() < 0.330% chance of true
array[Math.floor(Math.random() * array.length)]Random element from array
Math.random() returns 0 ≤ x < 1
Use Math.floor() to convert to whole numbers
Fisher-Yates algorithm for unbiased shuffling
Don't use for security! Use crypto.getRandomValues()