您能帮我解决我的问题吗?我使用了 javaScript window.crypto.getRandomvalues 函数,适用于所有浏览器,除了 safari Web 浏览器和我的 safari 浏览器版本 5.1.7。请找到我的代码
if ("crypto" in window && "getRandomValues" in crypto)
rand = crypto.getRandomValues(new Uint8Array(1))[0] % 16|0;
else rand = Math.random() * 16 | 0;
return hexs[i === 19 ? rand & 0x3 | 0x8 : rand];
})
请找到屏幕截图。这是我的错误: [截图][1] /image/Z1aYk.png
最佳答案
The array given as the parameter is filled with random numbers.
这并不意味着它返回一个充满随机数的数组。 因此,像这样更改您的代码:
if ("crypto" in window && "getRandomValues" in crypto){
var arr = new Uint8Array(1);
crypto.getRandomValues(arr)
rand = arr[0] % 16|0;
}
关于javaScript window.crypto.getRandomvalues 在 safari 浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34625695/