Skip to content

Instantly share code, notes, and snippets.

@nyawach
Created April 18, 2017 09:46
Show Gist options
  • Save nyawach/431ce02558530e1c5be7088a26df642a to your computer and use it in GitHub Desktop.
Save nyawach/431ce02558530e1c5be7088a26df642a to your computer and use it in GitHub Desktop.
[a-zA-Z0-9]のランダムな文字列を出力する
getRandomString(length = 8) {
// 生成する文字列に含める文字セット
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
let r = "";
for(let i = 0, charsLength = chars.length; i < charsLength; i++){
r += chars[Math.floor(Math.random()*cl)];
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment