Random value generators come up in a lot of different situations. This snippet collection consists of a variety of JavaScript solutions, from generating random numbers in a range to strings, booleans and hex color codes.
Generates a random number in the specified range.
JavaScript, Math · Oct 22, 2020
Generates a random integer in the specified range.
JavaScript, Math · Oct 22, 2020
Generates an array of n
random integers in the specified range.
JavaScript, Math · Oct 22, 2020
Generates a random string with the specified length.
JavaScript, String · Oct 22, 2020
Generates Gaussian (normally distributed) random numbers.
JavaScript, Math · Apr 3, 2023