mardi 22 décembre 2015

Randomize string and add to listbox

I'm having trouble randomizing X-amounts of strings and adding them to my listbox. it keeps adding the same string over and over. i want it to add 1 line per string. if i say that amount is 11, it just makes one string and adds it 11 times to listbox. what am i doing wrong?

here is my code:

for (int i = 0; i < amount; i++)
        {

            Random adomRng = new Random();
            string rndString = string.Empty;
            char c;

            for (int t = 0; t < 8; t++)
            {
                while (!Regex.IsMatch((c = Convert.ToChar(adomRng.Next(48, 128))).ToString(), "[a-z0-9]")) ;
                rndString += c;
            }

            listBox1.Items.Add(rndString);
        }




Aucun commentaire:

Enregistrer un commentaire