Random初始化只取一次

This commit is contained in:
lishuo 2024-02-01 10:09:34 +08:00
parent b07be239fd
commit c3a9437fc8

View File

@ -36,30 +36,31 @@ namespace OnlineUserPool.Hander
UpdateVirtualTime = DateTime.Now;
}
}
private Random rand = new Random();
//根据当前时段计算虚拟总人数
private int ComputeTop()
{
var rand = new Random();
var hour = DateTime.Now.Hour;//当前点数
int offset = 1;//少1 中3 多10
int top = 1;//少1 中3 多10
if (hour <= 6)
{
offset = rand.Next((int)(0.8 * START), (int)(1.2 * START));
top = rand.Next((int)(0.8 * START), (int)(1.2 * START));
}
if (hour > 6 && hour <= 18)
{
offset = rand.Next((int)(0.8 * OFFSET), (int)(1.2 * MEDIUM));
top = rand.Next((int)(0.8 * OFFSET), (int)(1.2 * MEDIUM));
}
if (hour >= 18 && hour <= 22)
{
offset = rand.Next((int)(0.8 * LARGE), (int)(1.2 * LARGE));
top = rand.Next((int)(0.8 * LARGE), (int)(1.2 * LARGE));
}
if (hour > 22 && hour <= 24)
{
offset = rand.Next((int)(0.8 * SMALL), (int)(1.2 * SMALL));
top = rand.Next((int)(0.8 * SMALL), (int)(1.2 * SMALL));
}
return offset;
return top;
}
/// <summary>