Skip to content

Instantly share code, notes, and snippets.

@gurdiga
Created December 28, 2013 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gurdiga/8163432 to your computer and use it in GitHub Desktop.
Save gurdiga/8163432 to your computer and use it in GitHub Desktop.
function randomPassword(lenght) {
function random() {
return parseFloat('.' + crypto.getRandomValues(new Uint32Array(1))[0]);
}
var characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
password = '',
i;
for (i = 0; i < 10; i++)
characters += characters;
for (i = 0; i < lenght; i++) {
password += characters.charAt(Math.floor(random() * characters.length));
}
return password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment