Skip to content

Instantly share code, notes, and snippets.

@pedrocss
Last active July 10, 2017 16:56
Show Gist options
  • Save pedrocss/89a125678371a4efff0561c3e6c8a162 to your computer and use it in GitHub Desktop.
Save pedrocss/89a125678371a4efff0561c3e6c8a162 to your computer and use it in GitHub Desktop.
util.cs
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