Generate Random String from signs and letters - Node.js String

Node.js examples for String:String Value

Description

Generate Random String from signs and letters

Demo Code


function generateRandomString(length){
  var charset = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ123456789 !"#$%&\'()*+,-./:;<=>?@[\\]_{}';
  var randomValues = new Uint8Array(length);
  crypto.getRandomValues(randomValues);//w  w w .  j av a 2 s. c om
  var string = '';
  for(var i = 0; i < length; i++){
    string += charset[randomValues[i]%charset.length];
  }
  return string;
}

Related Tutorials