可能重复:
C#中随机数生成器未按计划工作
我有基础的C#编程经验,目前正在制作一个骰子滚动程序。此应用程序最多可以掷四个骰子。我的问题是骰子总是产生相同的结果。我使用了一种方法,其中随机数生成器生成从一到六的数字,然后选择相应的图像。我在每个图像框下面重复该方法,因为用户可以输入他们想要掷多少个骰子。我的问题是骰子每次都生成相同的图片。我做错了什么?
public Image displaypic(PictureBox box)
{
string picchoice;
int number;
Image picture = box.Image;
//Prevents Redundant Images
Image displaying = box.Image;
do
{
//picks a die to display
Random rand = new Random();
number = rand.Next(1, 7);
picchoice = number.ToString();
//select an image from the image selection method
picture = diepic(picture, picchoice);
}
while (picture == displaying);
//return image
return picture;
}