Skip to content

Instantly share code, notes, and snippets.

@alexlvovich
Created October 2, 2020 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlvovich/4e885ac263bdb14b290078dd5f2be201 to your computer and use it in GitHub Desktop.
Save alexlvovich/4e885ac263bdb14b290078dd5f2be201 to your computer and use it in GitHub Desktop.
random string generator with Linq
private static Random random = new Random();
public static string RandomString(int length)
{
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    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