# 随机数相同问题

0

Random rd = new Random(System.DateTime.Now.Millisecond);
dz = Math.Abs(dz);
if (dz > 12)
{
dz = rd.Next(0, 5) + rd.NextDouble();
dz = Math.Round(dz, 1);
}
if (d2 > 12)
{
dx = rd.Next(0, 5) + rd.NextDouble();
dy = rd.Next(0, 5) + rd.NextDouble();
d2 = Math.Round(Math.Sqrt(dx * dx + dy * dy), 1);
dy = Math.Round(dy, 1);
dx = Math.Round(dx, 1);
}

0

0

public int numduos()
{
Random random = new Random();
int[] number ={ 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
int num = random.Next(10);
return number[num];
//Comsole.WriteLine("这个数是：{0}", number[num]);
}

public string RandomNum()
{
string strchar = "1，2，3，42，34，23，452";
Random r = new Random(Guid.NewGuid().GetHashCode());
string[] arr = strchar.Split(',');

foreach (string s in arr)
{
int index = r.Next(0, arr.Length);
string strTemp = arr[index];
arr[index] = arr[0];
arr[0] = strTemp;
}

string aa = "";
foreach (string s in arr)
{
aa += s + ",";
}

string[] bb = aa.Split(',');
string cc = "";
for (int i = 0; i < 5; i++)
{
cc += bb[i] + ",";
}
return cc.Trim().Substring(0, cc.Trim().Length - 1).Replace(",", ",");

}

jason2013 | 园豆：1998 (小虾三级) | 2012-08-30 10:10

0

new Random(DateTime.Now.Ticks)

56180825 | 园豆：1570 (小虾三级) | 2012-08-30 10:11

0

wolfram | 园豆：109 (初学一级) | 2012-08-30 10:30

0

random rd 声名的位置有问题，你是不是每次用随机数的时候都Random rd = new Random(System.DateTime.Now.Millisecond);。那么对于你下面的程序来说rd种子是一样的。random是伪随机，种子一样，下面的程序就一样了。你考虑一下我的意见

0

您需要登录以后才能回答，未注册用户请先注册