Switch to a PRNG implementation that doesn't have a birthday problem.

This commit is contained in:
Ian Gulliver
2015-12-30 22:01:25 -08:00
parent 8cfa55c722
commit 6ee8dc4f05

View File

@@ -663,9 +663,12 @@ Cosmopolite.prototype.init_ = function() {
* @const
*/
Cosmopolite.prototype.uuid = function() {
var randomBytes = new Uint8Array(31);
window.crypto.getRandomValues(randomBytes);
var i = 0;
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
/** @type {number} */
var r = (Math.random() * 16) | 0;
var r = randomBytes[i++] % 16;
if (c == 'x') {
return r.toString(16);
} else {