Last active
December 12, 2015 02:28
-
-
Save carloscabo/4698468 to your computer and use it in GitHub Desktop.
#js #math #utils Generate random token
This file contains 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 to generate random numeric token. Usefull to append it at the end of URLs we don't want to be cached by the browser. <img src="/path/image.png?XXXXXXX"> */ | |
var rand = function() { | |
return Math.random().toString(36).substr(2); // remove '0.' | |
}; | |
var token = function(char_num) { | |
var token = rand() + rand(); // make it longer | |
token = token.substr(0, char_num); | |
return token; | |
}; | |
//token(6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment