private void btnExtraction_Click(object sender, EventArgs e)
{
if (input())//验证为否为空
{
string Num;
Num = txtNum.Text;
int sum = 0, total = int.Parse(Num);
int numbert = 6;
int i = 1;
int temp = 0;
int startnumber = 1, endnumber = 33;
int[] number = new int[34];
int[] random = new int[6];
for (i = 1; i <= endnumber; i++)
{
number[i] = i;
}
Random R = new Random();
temp = R.Next(startnumber, endnumber);
i = 1;
random[0] = temp;
do
{
for (i = 1; i < numbert; i++)
{
random[i] = 0;
temp = R.Next(startnumber, endnumber);
for (int j = 1; j <= i; j++)
{
if (temp != random[j])
{
random[i] = temp;
}
else
{
temp = R.Next(startnumber, endnumber);
}
}
}
sum = 0;
for (i = 0; i < numbert; i++)
{
sum += random[i];
}
} while (sum != total);
string test = "";
for (i = 0; i < numbert; i++)
{
test += random[i].ToString() + "
";
}
txtNum1.Text = random[0].ToString();
txtNum2.Text = random[1].ToString();
txtNum3.Text = random[2].ToString();
txtNum4.Text = random[3].ToString();
txtNum5.Text = random[4].ToString();
txtNum6.Text = random[5].ToString();
}
还是有重复的 为什么阿
[
本帖最后由 wwfhz123 于 2010-9-30 00:01 编辑 ]