Skip to content

Instantly share code, notes, and snippets.

@teocomi
Last active July 20, 2016 09:27
Show Gist options
  • Save teocomi/95d41c7b4062fa4b454e8a4a0732babf to your computer and use it in GitHub Desktop.
Save teocomi/95d41c7b4062fa4b454e8a4a0732babf to your computer and use it in GitHub Desktop.
Random friendly string
/// <summary>
/// Random ID Generator
/// more ideas: http://www.anotherchris.net/csharp/friendly-unique-id-generation-part-2/
/// </summary>
/// <param name="length">Length of the string</param>
/// <returns></returns>
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