I am currently generating UUIDs in Javascript using this function ( Create GUID / UUID in JavaScript? ):
lucid.uuid = function() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }); }
I understand that all randomness comes only from the Javascript Math.random () function, and I don't care if it matches the RFC for the UUID. I want to pack as much randomness as possible into a few bytes in a Javascript string. The above function gives about 128 bits of randomness. How small is the line (measured in UTF8 bytes sent over the wire in HTTP POST), can I insert 128 bits in Javascript? And how would I generate such a string?
Edit: this string will be part of the JSON object when sent to the server, so the characters that need to be escaped in the string are not very useful.
Ben dilts
source share