Just save random in class scope:
Random random = new Random(); private void button1_Click(object sender, EventArgs e) { int characters = Convert.ToInt32(comboBox1.SelectedIndex); string password = ""; for(int i = 0; i <= characters; i++) { password = password +charGen(); } label2.Text = password; } private char charGen() { char randomNumber = Convert.ToChar( random.Next(48, 57)); return randomNumber; }
Currently, it is seeded to almost one value every time you call charGen .
source share