Last active
July 10, 2017 16:56
-
-
Save pedrocss/89a125678371a4efff0561c3e6c8a162 to your computer and use it in GitHub Desktop.
util.cs
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 GerarStringAleatoria(int length) | |
{ | |
const string valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; | |
StringBuilder res = new StringBuilder(); | |
var cryptoResult = new byte[4]; | |
new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(cryptoResult); | |
int seed = BitConverter.ToInt32(cryptoResult, 0); | |
Random rnd = new Random(seed); | |
while (0 < length--) | |
res.Append(valid[rnd.Next(valid.Length)]); | |
return res.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment