Skip to content

Home

Random alphanumeric string

Generates a random string with the specified length.

const randomAlphaNumeric = length => {
  let s = '';
  Array.from({ length }).some(() => {
    s += Math.random().toString(36).slice(2);
    return s.length >= length;
  });
  return s.slice(0, length);
};

randomAlphaNumeric(5); // '0afad'

More like this

Start typing a keyphrase to see matching snippets.