Skip to content

Instantly share code, notes, and snippets.

@codenamejason
Created July 19, 2016 14:06
Show Gist options
  • Save codenamejason/b2c601c406a915f67cb108a7637c8da2 to your computer and use it in GitHub Desktop.
Save codenamejason/b2c601c406a915f67cb108a7637c8da2 to your computer and use it in GitHub Desktop.
Creates random string in C#
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var random = new Random();
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment