一个简单的金额平均分配函数(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;
}
//参数说明:总金额,总人数,最大金额为平均金额的倍率
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;
}
相关文章推荐
- C#.net编程创建Access文件和Excel文件的方法详解
- Web Services and C# Enums
- C#之参数线程
- VS2010 常用快捷键
- C#使用二分查找法判断指定字符的方法
- C#项目中发生PInvokeStackImbalance异常,堆栈不对称异常
- 逐步讲解快速排序算法及C#版的实现示例
- C#中的Action<>和Func<>
- C#简单判断字符编码的方法
- C#判断字符编码的方法总结(六种方法)
- C#实现的一款比较美观的验证码完整实例
- 基于Emgu CV的图像处理 第一章 环境配置
- C#实现数独计算器
- C#做的接口
- C#使用IrisSkin2.dll美化WinForm程序界面
- c# 软件更新实例
- c# 软件更新实例
- Ubuntu vsftp搭建和C# Winform FTP操作
- C# socket
- 【C#】第1章 VS2015中C#6的新特性