双色球随机小程序

 

//随机红球

protected void Button1_Click(object sender, EventArgs e)

Random rnd = new Random();
ArrayList list=new ArrayList ();
int big = 6;
for(int i=0;i <big;i++)
{
int num= rnd.Next(1,34);
if (!list.Contains(num))
{
list.Add(num);
}
else
{
big++;
}
}
int empty;
for(int i=0;i<list.Count-1;i++)
{
for(int j=i+1;j<list.Count;j++)
{
if ((int)list[i]>(int)list[j])
{
empty=(int)list[i];
list[i]=list[j];
list[j]=empty;

}
}
}

for(int i=0;i<list.Count;i++)
{

if ((int)list[i] < 10)
{
if (i == list.Count - 1)
{
TextBox1.Text += "0" + list[i].ToString();
}
else
{
TextBox1.Text += "0" + list[i].ToString() + ",";
}
}
else
{
if (i == list.Count - 1)
{

TextBox1.Text += list[i].ToString();

}
else
{
TextBox1.Text += list[i].ToString()+",";
}
}


}

}

//随机篮球

protected void Button2_Click(object sender, EventArgs e)
{

Random rnd = new Random();
int num = rnd.Next(1, 17);
if (num < 10)
{
TextBox2.Text ="0"+ num.ToString();
}
else
{
TextBox2.Text=num.ToString();
}

}

posted @ 2012-12-26 15:32  消沉  阅读(325)  评论(0编辑  收藏  举报