samedi 23 février 2019

Random String c#

This is my code. I cant understand why the n variable doesn't change when the loop loops. Right now it just writes the first random letter and do it ten times instead of making it random every loop.

            string[] alfa = new string[16]{
                "a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p"
            };

            using (var tw = new StreamWriter(@"../../data/" + 
             NewUsername.Text + "," + NewPassword.Text + "/ReFectorPassword.txt", true))
            {

                for (var i = 0; i < 10; i++)
                {

                    Random r = new Random();
                    int n = r.Next(16);

                    randomString = alfa[n];
                    tw.Write(randomString );
                }

            }




Aucun commentaire:

Enregistrer un commentaire