Skip to content

Instantly share code, notes, and snippets.

@walterhuangsz
Created November 5, 2012 09:46
Show Gist options
  • Save walterhuangsz/4016365 to your computer and use it in GitHub Desktop.
Save walterhuangsz/4016365 to your computer and use it in GitHub Desktop.
Reading by Amazing String
namespace AmazingString
{
class Program
{
private static Random random = new Random();
static void Main(string[] args)
{
string sentence = "Covariant and contravariant generic type parameters provide greater flexibility in assigning and using generic types";
string[] wordList = sentence.Split();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < wordList.Length; i++)
{
wordList[i] = amazingWord(wordList[i]);
builder.Append(" ");
builder.Append(wordList[i]);
}
Console.WriteLine(builder.ToString());
Console.ReadKey();
}
private static string amazingWord(string word)
{
int length = word.Length;
if (length > 3)
{
char[] wordLetters = word.ToCharArray();
int count = length - 2;
while (--count > 0)
{
int k = random.Next() % count;
char temp = wordLetters[k + 1];
wordLetters[k + 1] = wordLetters[count + 1];
wordLetters[count + 1] = temp;
}
return new string(wordLetters);
}
else
{
return word;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment