Created
July 22, 2018 07:35
-
-
Save NorikDavtian/0f8cf7faedcc471e21c8759606b56767 to your computer and use it in GitHub Desktop.
Generate random string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From https://github.com/spotify/web-api-auth-examples/blob/master/authorization_code/app.js#L25-L33