Created
June 15, 2011 10:36
-
-
Save csanz/1026860 to your computer and use it in GitHub Desktop.
Just a simple, mini short code generator.
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
// 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