namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnRandonGenerate_Click(object sender, EventArgs e)
{
int RanRangMin = Convert.ToInt32(tbRandonRangMin.Text);
int RanRangMax = Convert.ToInt32(tbRandonRangMax.Text);
int RanQty = Convert.ToInt32(tbRandonQty.Text);
int ChangeQty = Convert.ToInt32(tbChangeQty.Text);
int[] Buf = new int[RanRangMax - RanRangMin + 1];
for (int index = 0; index < Buf.Length; index++)
{
Buf[index] = index + RanRangMin;
}
Random Ran = new Random();
for (int index = 0; index < ChangeQty; index++)
{
int a = Ran.Next(0, Buf.Length - 1);
int b = Ran.Next(0, Buf.Length - 1);
int Tamp = Buf[a];
Buf[a] = Buf[b];
Buf[b] = Tamp;
}
int[] Result = new int[RanQty];
for (int index = 0; index < RanQty; index++)
{
Result[index] = Buf[index];
}
for (int index = 0; index < Result.Length; index++)
{
rtbResult.Text += Result[index].ToString() + ",";
}
}
}
}
沒有留言:
張貼留言