using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
ArrayList ar = new ArrayList();
private void Form1_Load(object sender, EventArgs e)
{
ar.Add("dee-u1");
ar.Add("dee-u2");
ar.Add("dee-u3");
ar.Add("dee-u4");
ar.Add("dee-u5");
}
public static void ShuffleArray(ArrayList source)
{
Random rnd = new Random();
for (int inx = source.Count - 1; inx > 0; --inx)
{
//get new randon number
int position = rnd.Next(inx);
//temporarily store the value of source[inx] to a variable
object temp = source[inx];
//set the value of the current index (inx) to the value of the item found
//on the random position generated earlier
source[inx] = source[position];
//put the earlier stored value to the location of the new randon generator
//which swaps their position
source[position] = temp;
}
}
private void button1_Click(object sender, EventArgs e)
{
ShuffleArray(ar);
listBox1.Items.Clear();
for (int a = 0; a <= ar.Count - 1; a++)
{
listBox1.Items.Add(ar[a].ToString());
}
}
}
}