Last active
December 25, 2015 18:18
-
-
Save blaswan/7019080 to your computer and use it in GitHub Desktop.
The function that creates 256 bits random string token
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
function randomToken(length) { | |
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz0123456789+/' | |
, string = '' | |
, randomNumber | |
, i; | |
length = length ? length : 32; | |
for (i = 0; i < length; i++) { | |
randomNumber = Math.floor(Math.random() * chars.length); | |
string += chars.substring(randomNumber, randomNumber + 1); | |
} | |
return string; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment