彩票
Random r1 = new Random();//建立一个随机数生成器 int lan = r1.Next(0, 17);//从0—16里面随机生成1个篮球 int[] hong = new int[6];//定义红球个数是6 int n = 0;//红球个数初始为0个 while (true) { if (n == 6)//红球个数随机抽到6个就停止 { break; } else//红球个数还不够6个 { int hq = r1.Next(0, 34);//从0-34中随机抽取红球 if (hong.Contains(hq))//红球重复,则继续抽取 { } else//红求不重复 { hong[n] = hq;//把抽到的红球放到集合里面 n++; } } } for (int i = 0; i < hong.Length - 1; i++) { for (int j = 0; j < hong.Length - 1 - i; j++) { if (hong[j] <= hong[j + 1]) { int zj = hong[j + 1]; hong[j + 1] = hong[j]; hong[j] = zj; } } } Console.WriteLine("抽到的蓝球为:" + lan); Console.WriteLine("抽到的红球为:"); for (int i = 0; i < hong.Length; i++)//输入排完序后的红球 { Console.WriteLine(hong[i] + ","); }