gpt4 book ai didi

javaScript window.crypto.getRandomvalues 在 safari 浏览器中不起作用

转载 作者:行者123 更新时间:2023-11-27 23:30:18 24 4
gpt4 key购买 nike

您能帮我解决我的问题吗?我使用了 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

最佳答案

基于documentation here :

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com