Overview
Why?
Randomization can improve user experience by:
Creating surprise and delight through unpredictable interactions
Reducing pattern fatigue by varying content background images, quotes, colors, etc.
Output unexpected and unplanned results via code
How?
Use JavaScript's
Math
object andrandom()
method
What?
Math.random()
gives you a random decimal number between 0 and 1Includes 0 but never exactly 1
Think of it like rolling a 100-sided die, but with infinite sides between 0 and 1.
You might get:
0.72381...
0.00025...
0.5...
Last updated