Created
December 6, 2018 10:17
-
-
Save ibrahimatay/262f44c3c4d168b998490b5bbebda0cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static string RandomString(int length) | |
| { | |
| char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray(); | |
| byte[] data = new byte[length]; | |
| using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()) | |
| { | |
| crypto.GetBytes(data); | |
| } | |
| StringBuilder result = new StringBuilder(length); | |
| foreach (byte b in data) | |
| { | |
| result.Append(chars[b % (chars.Length)]); | |
| } | |
| return result.ToString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment