随机多人红包

/// <summary>
/// 随机多人红包
/// </summary>
/// <param name="totalCount">红包数量</param>
/// <param name="totalAmount">红包总金额</param>
/// <param name="minAmount">最小金额</param>
/// <param name="maxAmount">最大金额</param>
/// <returns></returns>
public static List<int> GetRandomMoneyList(int totalCount, int totalAmount, int minAmount, int maxAmount)
{
List<int> list = new List<int>();
string msg = string.Empty;
var pool = totalAmount - minAmount * totalCount;
var restNum = totalCount; // 剩余人数
var restPool = pool; // 剩余奖金
var restAmount = totalAmount;
for (var i = 0; i < totalCount; i++)
{
var range = maxAmount - minAmount;
var minS = restNum * range > restPool ? (restNum - 1) * range > restPool ? 0 : restPool % range : range;
var temp = minS + (int)Math.Round(rnd.NextDouble() * (maxAmount - minAmount - minS));
temp = temp > restPool ? restPool : temp;
restPool -= temp;
var prize = minAmount + temp;
list.Add(prize);
restNum--;
restAmount -= prize;
log.Normal("第" + (i + 1) + "个人:" + prize + "剩余奖金池:" + restAmount + ";");
}
return list;
}

posted @ 2017-04-13 09:56  毛丹  阅读(115)  评论(0编辑  收藏  举报