Created
January 16, 2017 13:13
-
-
Save agoalofalife/94ea286c6aab9b8c5da7021f60a83323 to your computer and use it in GitHub Desktop.
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
/** | |
* Generates unique id (mix datetime and random). | |
* @param {number=} len Required length of id (16 by default). | |
* @returns {string} Generated id. | |
*/ | |
function genUID(len){ | |
function base36(val){ | |
return Math.round(val).toString(36); | |
} | |
// uid should starts with alpha | |
var result = base36(10 + 25 * Math.random()); | |
if (!len) | |
len = 16; | |
while (result.length < len) | |
result += base36(new Date * Math.random()); | |
return result.substr(0, len); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment