window.crypto.getRandomValues

 

 

 

 

var arr = new Uint8Array(8);
var crypto = window.crypto || window.webkitCrypto || window.mozCrypto || window.oCrypto || window.msCrypto;
if (crypto) {
  crypto.getRandomValues(arr);
} else {
  // 如果浏览器不支持window.crypto,则使用Math.random()作为备选方案
  for (var i = 0; i < arr.length; i++) {
    arr[i] = Math.floor(Math.random() * 256);
  }
}
console.log(arr);

 

posted @ 2023-10-27 11:49  AngDH  阅读(274)  评论(0编辑  收藏  举报