Skip to content

Instantly share code, notes, and snippets.

@jltrem
Created August 12, 2014 21:43
Show Gist options
  • Save jltrem/3caa7d910f976c6dc3b0 to your computer and use it in GitHub Desktop.
Save jltrem/3caa7d910f976c6dc3b0 to your computer and use it in GitHub Desktop.
get random strings for use in testing
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