Skip to content

Instantly share code, notes, and snippets.

@gabalafou
Last active August 29, 2015 14:23
Show Gist options
  • Save gabalafou/66f04297c0f03dee7d20 to your computer and use it in GitHub Desktop.
Save gabalafou/66f04297c0f03dee7d20 to your computer and use it in GitHub Desktop.
Disqus client-side session id generating function
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