Skip to content

Instantly share code, notes, and snippets.

@blaswan
Last active December 25, 2015 18:18
Show Gist options
  • Save blaswan/7019080 to your computer and use it in GitHub Desktop.
Save blaswan/7019080 to your computer and use it in GitHub Desktop.
The function that creates 256 bits random string token
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