public ArrayList jixuanqiu(ArrayList red) //定义一个集合类型的函数
{
Random r = new Random(); //机选6个红球的过程并排序
while (true)
{
if (red.Count == 6)
{
break;
}
else
{
int temp = r.Next(1, 34);
if (!red.Contains(temp))
{
red.Add(temp);
}
}
}
red.Sort();
return red;
}
static void Main(string[] args)
{
while (true)
{
Random r = new Random();
ArrayList red = new ArrayList();
new Program().jixuanqiu(red);
//输出函数
Console.Write("红球为:");
for (int i = 0; i < 6; i++)
{
Console.Write(red[i] + "\t");
}
Console.Write("蓝球为:" + r.Next(1, 17));
Console.ReadLine();
}
时间: 2024-10-25 14:24:48