From 8c10dcf1970d6a0477fa746ff60f965574171cdb Mon Sep 17 00:00:00 2001 From: Stephen Johnston Date: Fri, 26 Oct 2018 09:04:44 -0400 Subject: [PATCH] updates (#3162) --- src/utils.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 77dfe10c918..93b19485dfe 100644 --- a/src/utils.js +++ b/src/utils.js @@ -66,10 +66,22 @@ exports.getUniqueIdentifierStr = _getUniqueIdentifierStr; */ exports.generateUUID = function generateUUID(placeholder) { return placeholder - ? (placeholder ^ Math.random() * 16 >> placeholder / 4).toString(16) + ? (placeholder ^ _getRandomData() >> placeholder / 4).toString(16) : ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, generateUUID); }; +/** + * Returns random data using the Crypto API if available and Math.random if not + * Method is from https://gist.github.com/jed/982883 like generateUUID, direct link https://gist.github.com/jed/982883#gistcomment-45104 + */ +function _getRandomData() { + if (window && window.crypto && window.crypto.getRandomValues) { + return crypto.getRandomValues(new Uint8Array(1))[0] % 16; + } else { + return Math.random() * 16; + } +} + exports.getBidIdParameter = function (key, paramsObj) { if (paramsObj && paramsObj[key]) { return paramsObj[key];