Skip to content

Instantly share code, notes, and snippets.

@csanz
Created June 15, 2011 10:36
Show Gist options
  • Save csanz/1026860 to your computer and use it in GitHub Desktop.
Save csanz/1026860 to your computer and use it in GitHub Desktop.
Just a simple, mini short code generator.
// For Nodejs
const crypto = require('crypto');
/**
* Get Short Code
*
* Mini Short Code Generator
*
* @param {Number} size
*
* @helper public
* @return String
*/
exports.get_short_code = function(size){
var random = Math.floor(Math.random()*999999) + '';
var md5crypto = crypto.createHash('md5').update(random).digest("hex");
var short_code = md5crypto.substring(0, size);
return short_code; // Ha! BOOM
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment