相关疑难解决方法(0)

随机数生成器仅生成一个随机数

我有以下功能:

//Function to get random number
public static int RandomNumber(int min, int max)
{
    Random random = new Random();
    return random.Next(min, max);
}
Run Code Online (Sandbox Code Playgroud)

我怎么称呼它:

byte[] mac = new byte[6];
for (int x = 0; x < 6; ++x)
    mac[x] = (byte)(Misc.RandomNumber((int)0xFFFF, (int)0xFFFFFF) % 256);
Run Code Online (Sandbox Code Playgroud)

如果我在运行时使用调试器执行该循环,则会得到不同的值(这就是我想要的).但是,如果我在该代码下面放置一个断点两行,则"mac"数组的所有成员都具有相同的值.

为什么会这样?

c# random

741
推荐指数
8
解决办法
17万
查看次数

标签 统计

c# ×1

random ×1