您的位置:首页 > 编程语言 > C#

一个简单的金额平均分配函数(C#版)

2016-06-13 11:02 330 查看
//总金额平均分配给总人数

//参数说明:总金额,总人数,最大金额为平均金额的倍率

public double[] GetList(double zje,int zrs,int max)
{
double total = zje;//总金额
int count = zrs;//总人数
double avg = total / count;
double[] list = new double[count];
int seed = 1;
while (count > 0)
{
if (count == 1)
{
list[zrs- count] = Math.Round(total,2);
count--;
}
else
{
Random r = new Random(seed);
double lv = (double)r.Next(max*100) / 100;
if (total - avg * lv <= 0)
{
seed++;
continue;
}
list[60 - count] = Math.Round(avg * lv,2,MidpointRounding.AwayFromZero);
total -= Math.Round(avg * lv, 2, MidpointRounding.AwayFromZero);
count--;
}
seed++;
}
return list;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: