private List<int> GetAll(int min, int max, DateTime fromDate, DateTime toDate)
{
if (min > max || fromDate > toDate)
{
return null;
}
List<int> list = new List<int>();
list.Add(min);
int totalDays = toDate.Subtract(fromDate).Days;
Random rand = new Random();
for (int i = 1; i < totalDays - 1; i++)
{
int temp = min;
temp += (int)(((max - min) / (totalDays - i - 1)) * rand.NextDouble());
if (temp < max)
{
min = temp;
}
else
{
min = max;
}
list.Add(temp);
}
list.Add(max);
return list;
}
调用:
DateTime fromDate = DateTime.Parse("2009-1-1");
DateTime toDate = DateTime.Parse("2009-2-1");
List<int> list = GetAll(48903, 49680, fromDate, toDate);
{
if (min > max || fromDate > toDate)
{
return null;
}
List<int> list = new List<int>();
list.Add(min);
int totalDays = toDate.Subtract(fromDate).Days;
Random rand = new Random();
for (int i = 1; i < totalDays - 1; i++)
{
int temp = min;
temp += (int)(((max - min) / (totalDays - i - 1)) * rand.NextDouble());
if (temp < max)
{
min = temp;
}
else
{
min = max;
}
list.Add(temp);
}
list.Add(max);
return list;
}
调用:
DateTime fromDate = DateTime.Parse("2009-1-1");
DateTime toDate = DateTime.Parse("2009-2-1");
List<int> list = GetAll(48903, 49680, fromDate, toDate);
你先用当前月M的用电数C1除以当前月M的天数D1,得到mp1(取整数)
然后你定义一个上下波动幅度F,第一天的用电数md1 = mp1 + (random.next(0,F) - 2*F)
剩下的总用电数C2=C1-mp1,然后用C2除以剩下的天数D2,得到mp2(取整数)
第二天的用电数md2 = mp2 + (random.next(0,F) - 2*F)
然后依次类推就行了,当然,你得注意,如果是最后一天则不需要随机数了哦
思路有了,代码实现应该不难
http://www.google.cn/search?client=pub-5434506002917399&prog=aff&channel=2000052003&q=%E6%8F%92%E5%80%BC%E7%AE%97%E6%B3%95