This is what I do to create compact 96 bit UIDs in a fast way. 4 bits
are per 6 characters but thats ok for me.
var uid = function() {
var mime
='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var ua = [];
for(var a = 0; a < 3; a++) {
var r32 = Math.floor(0x100000000 * Math.random());
for(var b = 0; b < 6; b++) {
ua.push(mime[r32 & 0x3F]);
r32 = r32 >>> 6;
}
}
return ua.join('');
};
I considered adding Date(), but figured it doesnt help me at all for
possible collisions generated in the very moment (from multiple hosts)
It may vary on the use case but I can handle collisions well with UIDs
generated long ago, but not with the ones created in parallell. So in
that case the space taken by Date() is far better used by yet another
random() entity. I also use this notation to save space rather than
the standarized UID type 4 things.
Yes it is also not cryptographically strong, but in my case that isn't
an issue and speed is more important. Also the web clients need to be
able to create UIDs and that cancels out a lot possibilities anyway
that might be available in node.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en