Skip to content

Instantly share code, notes, and snippets.

@carloscabo
Last active December 12, 2015 02:28
Show Gist options
  • Save carloscabo/4698468 to your computer and use it in GitHub Desktop.
Save carloscabo/4698468 to your computer and use it in GitHub Desktop.
#js #math #utils Generate random token
/* 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