Generate random string with native JavaScript

This article goes over how to generate a random string with native JavaScript:


Generate string with Math.random:

// '0.kq72bptq60s'

Generate string with Math.random without the period:

(Math.random() * 1e17).toString(36);
// 'k7bk5iit9io'

Generate string with;
// 'l243fe20'

Generate string with and Math.random:

( * Math.random()).toString(36);
// 'hrl8r78d.88'

Generate string with and Math.random without the period:

( * Math.random() * 1e5).toString(36);
// 'fc7gf0tyc6g'

Random Letter Case

Randomize letter case:

function randomCase(string) {
  return string
    .map((letter) => (Math.random() > 0.5 ? letter.toUpperCase() : letter))

Randomize letter case given string generated with Math.random:

// '0.2vLmxFrq4l2'

Please support this site and join our Discord!