Ale*_*lex 2 c# random numbers winforms
有没有什么好方法用C#生成随机偶数?我想出了这段代码:
Random RandString = new Random(0);
Run Code Online (Sandbox Code Playgroud)
码:
private void button6_Click(object sender, EventArgs e)
{
int min = 0;
int max = 50;
int rand = RandString.Next(min, max-1);
while (rand % 2 == 1) // odd
{
rand = RandString.Next(min, max-1);
}
textBox4.Text = "" + rand;
}
Run Code Online (Sandbox Code Playgroud)
这段代码有问题:
那么有什么方法可以解决我所描述的问题,还是有其他方法?
textBox4.Text = (2 * rand.Next(min / 2, max / 2)).ToString();
Run Code Online (Sandbox Code Playgroud)