From 6ee8dc4f05d09d4afdcb4a377dbbd73965bb0e6b Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Wed, 30 Dec 2015 22:01:25 -0800 Subject: [PATCH] Switch to a PRNG implementation that doesn't have a birthday problem. --- static/cosmopolite.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/static/cosmopolite.js b/static/cosmopolite.js index 0f7326b..09dd235 100644 --- a/static/cosmopolite.js +++ b/static/cosmopolite.js @@ -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 {