I have a program that creates a given number of folders named from a text file. I have the following algorithm:
private void button2_Click(object sender, EventArgs e)
{
if (path != null && Directory.Exists(path))
{
Random rnd = new Random();
for (int i = 0; i < value; i++)
{
var lines = File.ReadAllLines(path1);
var randomLineNumber = rnd.Next(0, lines.Length);
var line = lines[randomLineNumber];
StringBuilder b = new StringBuilder();
for (int j = 0; j < line.Length; j++)
{
char c = line[j];
if (rnd.Next(2) == 0)
{
c = Char.ToUpper(c);
}
b.Append(c);
if (j % 2 == 1)
{
b.Append(rnd.Next(10));
}
}
line = b.ToString();
Directory.CreateDirectory(Path.Combine(path, line));
}
}
}
I have a text file with one word on each line. My algorithm should take a random word from it and rename the folders that I create following the next rule:
lldlldll...ll and so on, where:
l - letter (upper case or lower case - it should be random)
d - digit
Real example:
Number of folders: 13
My list:
computer
explore
wireless
dog
love
electrical
phone
alex
andrew
elevator
door
Desired output:
aN5dR0ew7
dO1G6
DO3oR5
CO4mP7uT6er8
pH6ON1e
al9EX5
eX0pl9Or4e
EL5eC0Tr8iC0aL7
lO4vE2
wi1re9le6Ss47
el3eV0AT8oR9
Actual output:
aN5dR0ew7
dO1G6
DO3oR5
DO4G7
DO6g1
Do9G1
eL4Ec6TR5Ic3Al9
EL5eC0Tr8iC0aL7
eX2Pl6OR7E8
wi1re9le6Ss47
Wi8Re7Le6ss54
The problem is the next one:
If I create 20 folders and I also have 20 words in that .txt file, the algorithm will not use all of the words but just some of them ( and it will repeat them 3 times). The digits are ok / the upper-lower letters are ok. I just have to be sure that each word from that txt will be used.
Any help please ?