在大多的代码安全扫描软件扫描前端代码时,都会报Math.random()不安全,但是绝对随机数又是很难获取。只好采用以下方法...效果还行
// 兼容ie获取随机数(安全)
if (!window.crypto) {
if (broweserV === 11) {
window.cryptoCustom = function() {
return window.msCrypto.getRandomValues(new window.Uint8Array(1));
};
} else {
window.cryptoCustom = function() {
return Math.random();
};
}
} else {
window.cryptoCustom = function() {
return window.crypto.getRandomValues(new window.Uint8Array(1));
};
}