static void Main(string[] args) { for (int k = 0; k < 10; k++) { //输入 Console.WriteLine("请输入要生成的彩票种类:1代表双色球,2代表36选7"); int sr = Convert.ToInt32(Console.ReadLine()); //判断输入的数 if (sr == 1) { shuangseqiu(); //双色球函数 } else if (sr == 2) { caipiao(); //36选7的函数 } } } //双色球的函数 public static void shuangseqiu() { //生成蓝球 Random rd = new Random(); int lan = rd.Next(1, 16); int[] hong = new int[6]; //生成红球 for (int i = 0; i < 6; i++) { int h = rd.Next(1, 33); bool cf = false; for (int j = 0; j < hong.Length; j++) { if (hong[j] == h) { cf = true; break; } else { } } if (cf == true) { i--; } else { hong[i] = h; } } Console.WriteLine("蓝球是:" + lan); Console.WriteLine("红球是:" + hong[0] + "," + hong[1] + "," + hong[2] + "," + hong[3] + "," + hong[4] + "," + hong[5]); } //生成36选7 的函数 public static void caipiao() { Random rd = new Random(); int[] qiu = new int[7]; //生成球 for (int i = 0; i < 7; i++) { int h = rd.Next(1, 36); bool cf = false; for (int j = 0; j < qiu.Length; j++) { if (qiu[j] == h) { cf = true; break; } else { } } if (cf == true) { i--; } else { qiu[i] = h; } } Console.WriteLine("生成的7个数为:" + qiu[0] + "," + qiu[1] + "," + qiu[2] + "," + qiu[3] + "," + qiu[4] + "," + qiu[5]+","+qiu[6]); }
时间: 2024-11-09 09:28:16