我要打乱顺序的不要用到Array
namespace HW7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int[] num = new int[7];
private void Form1_Load(object sender, EventArgs e)
{ Random rnd1 = new Random();
for (int i = 0; i <= 6; i++)
{
num[i] = rnd1.Next(1, 49);
}
textBox1.Text = num[0].ToString();
textBox2.Text = num[1].ToString();
textBox3.Text = num[2].ToString();
textBox4.Text = num[3].ToString();
textBox5.Text = num[4].ToString();
textBox6.Text = num[5].ToString();
textBox7.Text = num[6].ToString();
}
}
}我产生了随机数。。可是我不行里面的数字重复应该怎么弄?
namespace HW7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int[] num = new int[7];
private void Form1_Load(object sender, EventArgs e)
{ Random rnd1 = new Random();
for (int i = 0; i <= 6; i++)
{
num[i] = rnd1.Next(1, 49);
}
textBox1.Text = num[0].ToString();
textBox2.Text = num[1].ToString();
textBox3.Text = num[2].ToString();
textBox4.Text = num[3].ToString();
textBox5.Text = num[4].ToString();
textBox6.Text = num[5].ToString();
textBox7.Text = num[6].ToString();
}
}
}我产生了随机数。。可是我不行里面的数字重复应该怎么弄?
Random rand = new Random(Guid.NewGuid().GetHashCode());
rand.Next(最小值,最大值)Enumerable.Range(1, 49).OrderBy(Guid.NewGuid());