首页 > 其他 > 详细

根据权重生成随机数

时间:2019-02-19 17:00:19      阅读:261      评论:0      收藏:0      [点我收藏+]
//function randomReward()
    //{
    //    const pIntegral = checkInConfig.pIntegral;
    //    let randomList = [];
    //    let weight = [];
    //    for (var i in pIntegral)
    //    {
    //        for (let j of Object.keys(pIntegral[i]).sort())
    //        {
    //            var key = j >> 0;
    //            randomList.push(key);
    //            weight.push(pIntegral[i][key]);
    //        }
    //    }
    //    let max = Math.min.apply(null, weight);
    //    //由于配置文件的问题:权重最小出现频率越高。后期可根据需求修改为:var max = Math.max.apply(null, weight);
    //    for (var i in pIntegral)
    //    {
    //        var maxObj = findKey(pIntegral[i], max) >> 0;
    //        randomList.push(maxObj, maxObj, maxObj);
    //    }
    //    var randomValue = randomList[Math.floor(Math.random() * randomList.length)];
    //    return randomValue;
    //}

  

根据权重生成随机数

原文:https://www.cnblogs.com/w-s-l123/p/10402111.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!