public string RadomNumArray() { Random r = new Random(); int a = 0; int[] num = new int[6]; string text = ""; for (int i = 0; i < 6; i++) {//循环生成6个数字 a = r.Next(0, 99);//随机生成0到99之间的数字 num[i] = a; for (int k = 0; k < num.Length; k++) {//遍历数组 if (num[i] == num[k] && i != k) {//查找重复重新生成随机数字 num[i] = r.Next(0, 99); k = -1; } } //将数组转换为string类型传参 if (i == 0) text += num[i]; else text += "," + num[i]; } return text; }ps:新手一枚,仅供参考,实际功能、优化 有待测试
时间: 2024-10-24 06:00:06