Skip to content

Instantly share code, notes, and snippets.

@NorikDavtian
Created July 22, 2018 07:35
Show Gist options
  • Save NorikDavtian/0f8cf7faedcc471e21c8759606b56767 to your computer and use it in GitHub Desktop.
Save NorikDavtian/0f8cf7faedcc471e21c8759606b56767 to your computer and use it in GitHub Desktop.
Generate random string
/**
* From https://github.com/spotify/web-api-auth-examples/blob/master/authorization_code/app.js#L25-L33
* Generates a random string containing numbers and letters
* @param {number} length The length of the string
* @return {string} The generated string
*/
var generateRandomString = function(length) {
var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
@NorikDavtian
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment