Print Unique keys in C#.net
See the question and my original answer on StackOverflowDepending on the required key length, instead of using Random (if 'r' points to Random), you could base your random numbers on Guids (for 128-bit keys) or on what provides the RNGCryptoServiceProvider class.