/// <summary>
/// 产生红包数组
/// </summary>
/// <param name="cashCount">红包总金额</param>
/// <param name="peopleNumber">红包人数</param>
/// <returns></returns>
private List<int> DivideRedEnvelope(int cashCount, int peopleNumber)
{
List<int> redPackageList = new List<int>();
if (cashCount <= peopleNumber)
{
for (int i = 0; i < cashCount; i++)
{
redPackageList.Add(1);
}
return redPackageList;
}
Random random = new Random();
int restCash = cashCount, restPeople = peopleNumber;
for (int i = 0; i < peopleNumber - 1; i++)
{
//var cash = random.Next(1, restCash / restPeople * 2);
int cash;
if (peopleNumber < 5)
{
var bound = (int)(restCash / restPeople / restPeople);
cash = restCash / restPeople + random.Next(-bound, bound);
}
else
{
//cash = random.Next(1, restCash / restPeople * 2);
int min = restCash / restPeople / 2;
cash = random.Next(min == 0 ? 1 : min, restCash / restPeople * 2);
}
restCash -= cash;
restPeople--;
redPackageList.Add(cash);
}
redPackageList.Add(restCash);
return redPackageList;
}