static void Main(string[] args)
{
while (true)//一直循环
{
Random r = new Random();//创建随机函数r
int[] caipiao = new int[7];//创建数组caipiao含7个元素
for (int i = 0; i < 6; )//for循环给红球赋值
{
if (i == 0)//第一个红球 赋值
{
caipiao[i] = r.Next(1, 34);//随机函数取值1-33之间为caipiao[0]元素赋值
i++;//I++
}
else
{
int temp = r.Next(1, 34);//创建一个临时变量,值为随机1-33之间
for (int j = 0; j < i; )//循环遍历caipiao数组0-I位的元素
{
if (temp==caipiao[j])//比较临时变量temp与caipiao[j]的值是否相等
{
temp = r.Next(1, 34);//如果相等重新为temp赋值,
j = 0; //并且将j的值修改为0,用temp从头循环比较
}
else
{
j++; //如果无重复 则J++
}
}
caipiao[i] = temp; //结束循环比较时将temp赋值给caipiao[i]元素
i++; //I++
}
}
for (int i = 0; i < caipiao.Length - 1; i++) //冒泡排序!
{
for (int j = i+1; j < caipiao.Length - 1; j++)
{
int temp1 = 0;
if (caipiao[i] > caipiao[j])
{
temp1 = caipiao[i];
caipiao[i] = caipiao[j];
caipiao[j] = temp1;
}
}
}
caipiao[6] = r.Next(1, 17);//蓝球赋值
for (int i = 0; i < caipiao.Length; i++)//循环输出所有值
{
if (i==6)
{
Console.Write("蓝球:"+caipiao[i] + "\t");
}
else
{
Console.Write(caipiao[i] + "\t");
}
}
Console.WriteLine();
//string y="";
//ArrayList al = new ArrayList();
//al.Add(3);
//al.Add(5);
//al.Add(7);
//al.Insert(1, 9);
//for (int i = 0; i < al.Count; i++)
//{
// Console.WriteLine(al[i]);
//}
Console.ReadLine();
}
}