// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Text; class MainClass { private static Random rng = new Random(); public static string Password(int l) { string valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; StringBuilder sb = new StringBuilder(""); for(int i = 0; i < l; i++) { sb.Append(valid[rng.Next(valid.Length)]); } return sb.ToString(); } private static int CountDigits(string s) { int res = 0; for(int i = 0; i < s.Length; i++) { if(Char.IsDigit(s[i])) { res++; } } return res; } public static string Password(int l, int nodig) { string res; do { res = Password(l); } while(CountDigits(res) != nodig); return res; } public static void Main(string[] args) { for(int i = 0; i < 10; i++) { string kodeord = Password(8, 2); Console.WriteLine(kodeord); } } }