Last active
August 29, 2015 14:23
-
-
Save gabalafou/66f04297c0f03dee7d20 to your computer and use it in GitHub Desktop.
Disqus client-side session id generating function
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 generateSessionId() { | |
// remove 3 most significant digits as they don't change often | |
var time = +(new Date().getTime().toString().substring(3)); | |
// Doing only arithmetic operations here as bitwise shifts only operate on int32. | |
// Final number consists of two parts which should be independently random. Each part is | |
// converted to a number with base 32 in order to minimize overall length of the final number, | |
// but still keep it very random (14^32 different strings) | |
var id = Math.abs(time + getNavigationTime() - reduceMiscSessionMetrics()).toString(32); | |
id += random().toString(32); | |
return id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment