1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| function random(min = 0.01, max = 100) { return parseFloat((min + Math.random() * (max - min)).toFixed(2)) } function redPacket(amounts = 100, count = 10) { const result = [] while (count-- > 0) { if (count === 0) { result.push(amounts) break } const max = amounts - count * 0.01 const red = random(0.01, max) amounts = parseFloat((amounts - red).toFixed(2)) result.push(red) } return result }
|