I am in need of generating a random string with spaces and mixedCase.
This is all I got so far:
/// <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
{
/// <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();
Random random = new Random();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
builder.Append(ch);
}
return builder.ToString();
}
}
I am getting only uppercase strings with no spaces - I believe the tweak should be pretty striaghtforward to get mixed case and spaces in the soup.
Any help greatly appreciated!
You can also use Lorem Ipsum. It is widely used in the graphic design industry to fill in for random, realistic text without distracting the user from the design elements.
You can copy and paste a big chunk of the Lorem Ipsum into a constant string in your code and then just substring it into whatever sizes you need.
I found this was better than having completely random text since it was too distracting.
Hope that helps.
You could start with an array of all the characters you'll allow
And then:
I paraphrase, of course. I'm not certain about the syntax on random.NextInt(), but intelisense aught to help.
The easiest way to do this is to simply create a string with the following values:
Then use the RNG to access a random element in this string: