For writing a general purpose decoder a a personal project, I am trying to generate all alphanumeric combinations of any given length.
I have something along these lines functioning, but i highly doubt it will generate all of them, as it seem biased towards letter combinations.
Code:
{
string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
List<string> combinations = new List<string>();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
var random = new Random();
for (int x = 0; x <= 999; x++)
{
combinations.Add(chars[random.Next(chars.Length)].ToString());
for (int i = 0; i <= 8; i++)
{
combinations[x]+= chars[random.Next(chars.Length)].ToString();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
for (int x=0; x<99; x++)
{
Console.WriteLine(combinations[x]);
}
}
}
Can anyone explain to me how to generate all of them of any given length? I'm thinking of nested for loops, with conditional statements. So if combinations[x] < given length, then a for loops executes. Will this work? Or do you know a better method?
Greetings