使用随机数产生一组大乐透号码
1. C#代码
1 Console.WriteLine("===============大乐透===红色球===============");
List<int> listRed = new List<int>();
Random rangdomRed = new Random();
for (int i = ; listRed.Count < ; i++)
{
int redNum = rangdomRed.Next(, );
if (!listRed.Contains(redNum))
{
listRed.Add(redNum);
Console.Write("{0} ", redNum);
} }
Console.WriteLine();
Console.WriteLine("===============大乐透===蓝色球================");
List<int> listBlue = new List<int>();
Random rangdomBlue = new Random();
for (int i = ; listBlue.Count < ; i++)
{
int blueNum = rangdomBlue.Next(, );
if (!listBlue.Contains(blueNum))
{
listBlue.Add(blueNum);
Console.Write("{0} ", blueNum);
}
} Console.WriteLine();
Console.WriteLine("===============排序=============");
listRed.Sort();
for (int i = ; i < listRed.Count; i++)
{
Console.Write("{0} ", listRed[i]);
}
listBlue.Sort();
for (int i = ; i < listBlue.Count; i++)
{
Console.Write("{0} ", listBlue[i]);
}
Console.WriteLine(); Console.ReadKey();
2. 运行结果