I have this code which generates all the combination of characters possible for a given size of string:
public partial class Form1 : Form
{
List<string> characters = new List<string>();
string rip = "";
int size = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SetList();
}
public void SetList()
{
string[] numbers = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
string[] lowercase = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
string[] uppercase = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
characters.AddRange(numbers);
characters.AddRange(lowercase);
characters.AddRange(uppercase);
}
private void button1_Click(object sender, EventArgs e)
{
int x = 1;
Random rand = new Random();
while (x <= size)
{
int y = rand.Next(0, characters.Count - 1);
string ch = characters[y];
rip = rip + ch;
x++;
}
listBoxPasswords.Items.Add(rip);
rip = string.Empty;
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
size = Convert.ToInt32(numericUpDown1.Value);
}
}
}
However in order to retrieve all the combinations of the characters i need to push the button1 many times. Is there a way I can loop this somehow? I need this in order to make my app practical .
I will let the programm running while I do other things. I want my loop to generate the combinations of characters and print them in the form of a string to the listbox.