public static void Main(string[] args)
{
//组数
int index = 10;
Console.WriteLine("**************【十组】双色球***************");
for (int i = 0; i < index; i++)
{
string str = RedBlue();
System.Threading.Thread.Sleep(1000);
Console.WriteLine(str);
}
Console.WriteLine("******************************************");
Console.ReadKey(true);
}
public static string RedBlue()
{
string str = string.Empty;
Dictionary<int, int> dic = new Dictionary<int, int>();
str = "红色球:";
for (int i = 0; i <= 5; i++)
{
Random r = new Random();
int red = r.Next(1, 34);
while (dic.ContainsKey(red))
{
r = new Random();
red = r.Next(1, 34);
}
dic.Add(red, red);
str = str + red + " ";
}
Random b = new Random();
int blue = b.Next(1, 17);
str = str + " 蓝色球:" + blue;
return str;
{
//组数
int index = 10;
Console.WriteLine("**************【十组】双色球***************");
for (int i = 0; i < index; i++)
{
string str = RedBlue();
System.Threading.Thread.Sleep(1000);
Console.WriteLine(str);
}
Console.WriteLine("******************************************");
Console.ReadKey(true);
}
public static string RedBlue()
{
string str = string.Empty;
Dictionary<int, int> dic = new Dictionary<int, int>();
str = "红色球:";
for (int i = 0; i <= 5; i++)
{
Random r = new Random();
int red = r.Next(1, 34);
while (dic.ContainsKey(red))
{
r = new Random();
red = r.Next(1, 34);
}
dic.Add(red, red);
str = str + red + " ";
}
Random b = new Random();
int blue = b.Next(1, 17);
str = str + " 蓝色球:" + blue;
return str;
}
运行结果: