public int num = 100;
public int money = 2000;
public int max = 88;
public int min = 1;
private void DataBing()
{
Random rd = new Random();
List<int> list_ten = new List<int>();
for (int i = 0; i < 10; i++)
{
int count=rd.Next(80, 88);
money -= count;
list_ten.Add(count);
}
List<int> list = new List<int>();
//每个人先把最小金额拿到手
for (var i = 0; i < 90; i++)
{
list.Add(min);
}
//计算还剩下多少钱
money -= ((num-10) * min);
//随机分配,直到钱花完
while (money > 0)
{
//在0-99之间随机
int idx = rd.Next(0, 90);
if (list[idx] < max)
{
list[idx] += 1;
money -= 1;
}
}
for (int i = 0; i < list_ten.Count; i++)
{
list.Insert(i * i, list_ten[i]);
}
string a = "";
int b = 0;
for (int i = 0; i < list.Count; i++)
{
if (i % 10 == 0)
{
a += "<br/>";
}
a += list[i] + ",";
b += list[i];
}
Response.Write(a + "<br/>");
Response.Write(b);
}
本文出自 “相信自己我能行” 博客,请务必保留此出处http://7515975.blog.51cto.com/7505975/1745881