欧阳克2017-07-05 10:39:39
rpAmount = 100
ppCount = 10
rpResult=[]
rpRnds = []
rpRndSum = 0
for(let i=0;i<ppCount;i++){let rnd = Math.random();rpRndSum+=rnd;rpRnds.push(rnd);}
rpRnds.forEach((rnd)=>{rpResult.push(rpAmount*rnd/rpRndSum)})
console.log('rpResult',{rpResult,sum:rpResult.reduce((acc,val)=>{return acc+val})})
核心思想:
随机数直接确定的权重, 而非金额.