Javascript generate random string
snippet in javascript

javascript generate random string

user9020

// Generate a random alphanumerical string of length 11 ( change substring parameter for other length)
Math.random().toString(36).substring(2);

Javascript generate random string

user7730

function getRandomString(length) {
    var randomChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var result = '';
    for ( var i = 0; i < length; i++ ) {
        result += randomChars.charAt(Math.floor(Math.random() * randomChars.length));
    }
    return result;
}

//usage: getRandomString(20); // pass desired length of random string

how to generate random character from an array js

user5111

function makeid() {
  var text = "";
  var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

  for (var i = 0; i < 5; i++)
    text += possible.charAt(Math.floor(Math.random() * possible.length));

  return text;
}

console.log(makeid());

how to generate random string in javascript

user4642

 Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);

random alphabet javascript

user5420

Math.random().toString(36).substr(2, 5);

random text generator javascript

user2214

function getRandomText(length) {
  var charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".match(/./g);
  var text = "";
  for (var i = 0; i < length; i++) result += charset[Math.floor(Math.random() * charset.length)];
  return text;
}