SEO

以后地位:SEO > IT手艺

权重随机数列表

时辰:2019-08-10 19:10:00来历:IT手艺作者:搜刮引擎优化尝试室小编阅读:79次
 

随机数表

import cn.hutool.core.lang.WeightRandom;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

public class RandomUtil extends cn.hutool.core.util.RandomUtil {
/**
     * 按照权重列表天生牢固总量的数组
     *
     * @param weightList  权重列表
     * @param total  随机列表数的总和
     * @param fuDong     浮动指数
     * @return
     */
    public static <T> Map<T, integer> randomListFromWeight(List<WeightRandom.WeightObj<T>> weightList, Integer total, double fuDong) {
        if (!(fuDong > 0 && fuDong < 1)) {
            throw new illegalargumentException("浮动指数必须在0~1之间");
        }
        Map<T, Integer> result = new HashMap<>();
        // 将权重列表倒序摆列,保障权重高的优先取值
        weightList.sort(new Comparator<WeightRandom.WeightObj>() {
            @Override
            public int compare(WeightRandom.WeightObj o1, WeightRandom.WeightObj o2) {
                if (o1.getWeight() > o2.getWeight()) {
                    return -1;
                } else if (o1.getWeight() < o2.getWeight()) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });
        // 统计权重总和
        double sumWeight = weightList.stream().map(WeightRandom.WeightObj::getWeight).reduce((a, b) -> a + b).orElse(1.0 * weightList.size());
        // 计较均匀权重
        double avgWeight = sumWeight / weightList.size();
        // 计较均匀值
        double avg = 1.0 * total / weightList.size();
        int before = 0;
        for (int i = 0; i < weightList.size() - 1; i++) {
            // 现实值 = 均匀值 * 权重 / 均匀权重
            double countForWeight = avg * weightList.get(i).getWeight() / avgWeight;
            double min = before + countForWeight * (1 - fuDong);
            double max = before + countForWeight * (1 + fuDong);
            min = min > total ? before : min;
            max = max > total ? total : max;
            int after = min < max ? (int) Math.round(RandomUtil.randomDouble(min, max)) : total;
            result.put(weightList.get(i).getObj(), after - before);
            before = after;
        }
        // 最初一个的值
        result.put(weightList.get(weightList.size() - 1).getObj(), total - before);
        return result;
    }
}

相干阅读

淘宝宝贝被隐形降权该若何办?有甚么方式规复权重?

在良多时辰咱们能够会发现店肆或是宝贝的流量降落了,并且还延续了降落的趋向,这类环境下,良多人会感觉稀里糊涂,本身比来也不对店

ASO中批评权重下降?从六个角度说完这个题目

不管ASO人若何哀嚎批评的权重若何的在下降,都转变不了其是影响APP排名的身分之一。而有的ASO伴侣却以为,批评之途已尽,需重点从别的

淘宝加购物车和保藏有甚么区分?对店肆权重影响大吗

淘宝加购物车和保藏有甚么区分?现在良多卖家起头更正视加购了,由于加购影响到店肆的诸多方面,淘宝加购物车和保藏有甚么区分?对店肆权

matlab天生随机数的rand、randi和randn三种情势

  matlab中对于随机数的发生有3种库函数,上面咱们来看看它们的情势:   1、rand(…)   它是天生0~1之间(开环,不包罗0和1两个数

京东慢车搜刮权重飙升法:霸屏霸词法

有开京东慢车很利害的卖家伴侣,能够用自家的3个商品,持续攻克某个词,PC端慢车“商品精选”SEO推行位。最好状况是,3个商品别离排到这

分享到:

栏目导航

保举阅读

热点阅读

偷拍自拍图片janpanese强行18一19宝贝堵着不许流出来二哥tk4479周秀娜喜爱夜蒲片段梦精记qvodtvb40周年台庆 www.andxy.org www.zyktw.cn www.huosaigan.com.cn www.yuesao.zj.cn www.jshch.cn www.51qingjian.com www.315yzw.com www.0453d.com www.orienttp.com www.feaonlinebbs.cn www.lnsafety.com www.time100-watch.com www.kunluntop.com www.chic-china.com www.51jieneng.com www.shuangxihu.com www.Lbn100.com www.sxoven.com www.spirit-sh.com www.530wan.com www.gaojiange.net