Last active
July 20, 2016 09:27
-
-
Save teocomi/95d41c7b4062fa4b454e8a4a0732babf to your computer and use it in GitHub Desktop.
Random friendly string
This file contains 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
/// <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