Created
August 12, 2014 21:43
-
-
Save jltrem/3caa7d910f976c6dc3b0 to your computer and use it in GitHub Desktop.
get random strings for use in testing
This file contains hidden or 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
public static class TestUtil | |
{ | |
private static Random _random = new Random(); | |
public static string MakeRandomString(int numchars = 8) | |
{ | |
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; | |
return new string(Enumerable.Repeat(chars, numchars).Select(x => x[_random.Next(x.Length)]).ToArray()); | |
} | |
public static string MakeRandomWordString(int numwords = 4) | |
{ | |
string[] words = { "Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima", "Mike", | |
"November", "Oscar", "Papa", "Quebec", "Romeo", "Sierra", "Tango", "Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu" }; | |
var sb = new StringBuilder(); | |
for (int i = 0; i < numwords; i++) | |
{ | |
sb.Append(words[_random.Next(words.Length)] + " "); | |
} | |
return sb.ToString().Trim(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment