dorna20-30
پنج شنبه 16 خرداد 1392, 10:38 صبح
سلام دوستان:
من یه سری عدد از کاربر می گیرم ، داخل یه ارایه قرار می دم ،حالا می خوام این اعداد رو به صورت تصادفی وارد یه فایل کنم برای این کار از اعداد تصادفی استفاده می کنم.ولی باید این اعداد تصادفی غیر تکراری باشه.
میشه راهنماییم کنید.ممنون
//پر کردن آرایه
private void button3_Click(object sender, EventArgs e)
{
wr[i] = textBox1.Text;
i++;
textBox1.Text = "";
if (i == 3) { MessageBox.Show("ERROR"); }
}
string[] rando = new string[4];
private void button1_Click(object sender, EventArgs e)
{
int j=0;
int rand;
DialogResult result = savefile.ShowDialog();
if (result == DialogResult.OK)
{
string fln = savefile.FileName;
int n = wr.Length;
Random rnd = new Random();
while (j <= 2)
{
rand = rnd.Next(0, n);
MessageBox.Show(rand.ToString());
if (rand == 0) { rando[j] = wr[rand]; }
else
{
rando[j] = wr[rand - 1];
}
File.WriteAllLines(fln, rando);
j++;
}
}
}
من یه سری عدد از کاربر می گیرم ، داخل یه ارایه قرار می دم ،حالا می خوام این اعداد رو به صورت تصادفی وارد یه فایل کنم برای این کار از اعداد تصادفی استفاده می کنم.ولی باید این اعداد تصادفی غیر تکراری باشه.
میشه راهنماییم کنید.ممنون
//پر کردن آرایه
private void button3_Click(object sender, EventArgs e)
{
wr[i] = textBox1.Text;
i++;
textBox1.Text = "";
if (i == 3) { MessageBox.Show("ERROR"); }
}
string[] rando = new string[4];
private void button1_Click(object sender, EventArgs e)
{
int j=0;
int rand;
DialogResult result = savefile.ShowDialog();
if (result == DialogResult.OK)
{
string fln = savefile.FileName;
int n = wr.Length;
Random rnd = new Random();
while (j <= 2)
{
rand = rnd.Next(0, n);
MessageBox.Show(rand.ToString());
if (rand == 0) { rando[j] = wr[rand]; }
else
{
rando[j] = wr[rand - 1];
}
File.WriteAllLines(fln, rando);
j++;
}
}
}