亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - Use js to implement red envelope distribution problem
滿天的星座
滿天的星座 2017-07-05 10:37:39
0
3
961

100 yuan is given to 10 people in red envelopes. The size of the red envelope is random and everyone can get a red envelope

滿天的星座
滿天的星座

reply all(3)
學(xué)霸
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})})

Core idea:
The weight is directly determined by the random number, not the amount.

世界只因有你

You can take a look at this
/q/10...

曾經(jīng)蠟筆沒有小新

Idea: Use the random function to randomly allocate each time. The red envelope value obtained each time is greater than 0.01 and less than the remaining amount - the remaining number of people * 0.01. The last person can get all the remaining money

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template