Created
April 13, 2009 18:21
-
-
Save gidili/94600 to your computer and use it in GitHub Desktop.
TypingMonkey to generate random strings
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
/// <summary> | |
/// The Typing monkey generates random strings - can't be static 'cause it's a monkey. | |
/// </summary> | |
/// <remarks> | |
/// If you wait long enough it will eventually produce Shakespeare. | |
/// </remarks> | |
class TypingMonkey | |
{ | |
private const string legalCharacters = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890."; | |
static Random random = new Random(); | |
/// <summary> | |
/// The Typing Monkey Generates a random string with the given length. | |
/// </summary> | |
/// <param name="size">Size of the string</param> | |
/// <returns>Random string</returns> | |
public string TypeAway(int size) | |
{ | |
StringBuilder builder = new StringBuilder(); | |
char ch; | |
for (int i = 0; i < size; i++) | |
{ | |
ch = legalCharacters[random.Next(0, legalCharacters.Length)]; | |
builder.Append(ch); | |
} | |
return builder.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment