根据权重生成随机数

//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;
    //}

  

猜你喜欢

转载自www.cnblogs.com/w-s-l123/p/10402111.html