Skip to content

Instantly share code, notes, and snippets.

@tpatel
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save tpatel/36d232de12faf5695188 to your computer and use it in GitHub Desktop.

Select an option

Save tpatel/36d232de12faf5695188 to your computer and use it in GitHub Desktop.
Generate random hexadecimal token
var r = require('crypto').randomBytes,
punctuation = '-_!:;,?./*=',
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
p = function(t) {
return t[Math.floor(t.length*Math.random())];
},
res = p(punctuation)+p(uppercase)+r(16).toString('hex');
console.log(res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment