Console.WriteLine("How many times would you like to roll?");
string count = Console.ReadLine();
int cnt = Convert.ToInt32(count);
for (int i = 1; i <= cnt; i++)
{
int rol = new int();
Random roll = new Random();
rol = roll.Next(1, 6);
Console.WriteLine("Die {0} landed on {1}.", i, rol);
}
Console.ReadLine();
我想在C#中创建一个骰子滚动模拟器,但我遇到了一个问题:在第一次滚动后,随机数永远不会改变。发生了什么,我该如何解决它?随机函数刷新
在'for'循环之外移动'Random roll = new Random()'。 – Alex 2015-04-06 02:09:25