-
-
Save wawbz/07359baebf6ea2b7d4279eee528eec0d to your computer and use it in GitHub Desktop.
JavaScript function that copies functionality of PHP's 'uniqid'.
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
(function () { | |
this.uniqid = function (pr, en) { | |
var pr = pr || '', en = en || false, result; | |
this.seed = function (s, w) { | |
s = parseInt(s, 10).toString(16); | |
return w < s.length ? s.slice(s.length - w) : (w > s.length) ? new Array(1 + (w - s.length)).join('0') + s : s; | |
}; | |
result = pr + this.seed(parseInt(new Date().getTime() / 1000, 10), 8) + this.seed(Math.floor(Math.random() * 0x75bcd15) + 1, 5); | |
if (en) result += (Math.random() * 10).toFixed(8).toString(); | |
return result; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use: