谁帮我下随机数循环问题 求大大们帮下
条件:设一空数组 int[] Numint = new int [6]; 然后产生 随机数,放入数组,
目标: 数组里面没有想同的数值
不记得怎么写了,,求大大们帮下
int[] shuzu = new int[6]; int m; for (int i = 0; i < shuzu.Length; i++) { chongxinquzhi: //如果有重复就从这里重新开始随机 Random rand = new Random(); Thread.Sleep(15); m = rand.Next(100); for (int j = 0; j < shuzu.Length; j++)//判断是否重复 { int shuzhi = shuzu[j]; if (shuzhi == m) { goto chongxinquzhi;//有重复,重新随机 } } shuzu[i] = m; }