开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 7039|回复: 3
收起左侧

[火山PC分享] 关于火山v8js引擎 没有getRandomValues 这个的替换方案

[复制链接]
发表于 2021-10-11 10:30:33 | 显示全部楼层 |阅读模式   四川省德阳市
function randoms(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min)
}

function getRandomValues(buf) {
    var min = 0,
        max = 255;
    if (buf.length > 65536) {
        var e = new Error();
        e.code = 22;
        e.message = 'Failed to execute \'getRandomValues\' : The ' + 'ArrayBufferView\'s byte length (' + buf.length + ') exceeds the ' + 'number of bytes of entropy available via this API (65536).';
        e.name = 'QuotaExceededError';
        throw e;
    }
    if (buf instanceof Uint16Array) {
        max = 65535;
    } else if (buf instanceof Uint32Array) {
        max = 4294967295;
    }
    for (var element in buf) {
        buf[element] = randoms(min, max);
    }
    return buf;
}

function lxx() {
    var K = new Uint32Array(16);

    for (getRandomValues(K), G = 0; G < K.length; ++G) {
        var rx = K[G]
                var r = K.reduce((function(K, rx) {
                return K + rx.toString(16)
            }
            ), "");
                return r
    }

}

签到天数: 1 天

 楼主| 发表于 2021-10-16 12:04:47 | 显示全部楼层   四川省德阳市
落枫_rain 发表于 2021-10-11 11:14
本帖最后由 落枫_rain 于 2021-10-11 11:30 编辑
    window.crypto.getRandomValues = function(array){ ...

V8里没这个window.crypto.getRandomValues

点评

自己申明   广东省广州市  发表于 2021-10-19 14:58
回复 支持 反对

使用道具 举报

结帖率:100% (45/45)
发表于 2021-10-11 11:14:17 | 显示全部楼层   广东省广州市
本帖最后由 落枫_rain 于 2021-10-11 11:30 编辑
    window.crypto.getRandomValues = function(array){
        if (array === undefined)throw new TypeError("Failed to execute 'getRandomValues' on 'Crypto': 1 argument required, but only 0 present.");
        if (array.constructor.name === "Uint8Array" && array.length > 65536)throw new DOMException("Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (".concat(array.length) + ") exceeds the number of bytes of entropy available via this API (65536).","QuotaExceededError",22);
        if (array.constructor.name === "Uint16Array" && array.length > 32768)throw new DOMException("Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (".concat(array.length*2) + ") exceeds the number of bytes of entropy available via this API (65536).","QuotaExceededError",22);
        if (array.constructor.name === "Uint32Array" && array.length > 16384)throw new DOMException("Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (".concat(array.length*4) + ") exceeds the number of bytes of entropy available via this API (65536).","QuotaExceededError",22);
        if (array.constructor.name === "Uint8ClampedArray" && array.length > 65536)throw new DOMException("Failed to execute 'getRandomValues' on 'Crypto': The ArrayBufferView's byte length (".concat(array.length) + ") exceeds the number of bytes of entropy available via this API (65536).","QuotaExceededError",22);
        for (let key in array){
            array[key] = Math.random()*100000000;
        }
    }

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表