You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- package utils
-
- import (
- "math/rand"
- "time"
- )
-
- // RED_PACKET_MIN_MONEY 红包最小金额(单位:分)
- const RED_PACKET_MIN_MONEY = 1
-
- // DoubleAverage 二倍均值算法
- func DoubleAverage(count, amount int64) int64 {
- if count == 1 {
- return amount
- }
- //计算出最大可用金额
- max := amount - RED_PACKET_MIN_MONEY*count
- //计算出最大可用平均值
- avg := max / count
- //二倍均值基础上再加上最小金额 防止出现金额为0
- avg2 := 2*avg + RED_PACKET_MIN_MONEY
- //随机红包金额序列元素,把二倍均值作为随机的最大数
- rand.Seed(time.Now().UnixNano())
- x := rand.Int63n(avg2) + RED_PACKET_MIN_MONEY
- return x
- }
|