×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Paul Zz
Added: Mar 21, 2017 12:57 PM
Views: 11
Generates a short (up to 11 random characters) string. The string may contain letters in upper and lower cases and digits. Pass the desired string length as a function argument.
Don't use it in prodation.
  1. /**
  2. * @param {Number} length
  3. * @returns {String}
  4. */
  5. function simplePwGen (length) {
  6.   return Math.random().toString(36).replace(/0\./, '').split('').map(v => Math.round(Math.random()) ? v : v.toUpperCase()).join('').slice(-length);
  7. }