手机号抽奖、福利彩票抽奖
手机号排序
Console.WriteLine("请输入手机号的个数:"); int a = Convert.ToInt32(Console.ReadLine()); string[] sj = new string[a]; for (int i = 0; i < a; i++) { Console.WriteLine("请输入第{0}个手机号:", i + 1); sj[i] = Console.ReadLine(); } Console.WriteLine("*************************************"); // 抽奖 DateTime d = DateTime.Now; DateTime dt = d.AddSeconds(10);//10秒后自动抽取 while (true) { Console.Clear(); Random r = new Random(); int b = r.Next(a); Console.WriteLine(sj[b]); Thread.Sleep(100); if (DateTime.Now.ToString("yyyyMMddHHmmss") == dt.ToString("yyyyMMddHHmmss")) { break; } else { } } //Console.Clear(); //Console.WriteLine("15165339515"); 这个是做内定手机,先清屏,再输出
福利彩票抽奖
Random r = new Random(); int lan = r.Next(17); int [] hong = new int [6];//定义红球数组 int n = 0; while (true) { if (n == 6) { break; } else { int b = r.Next(34); if (hong.Contains(b)) { } else { hong[n]=b; 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 k = 0; k < hong.Length; k++) { Console.Write(hong[k]+","); } Console.ReadLine();