Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!

Markov Chain (Extended algorithm)

By: xxdriesxx on Jun 28th, 2011  |  syntax: C#  |  size: 0.98 KB  |  views: 174  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. var pattern = _patterns[_randomGenerator.Next(0, _patterns.Count)];
  2. var name = "";
  3. var currentRule = "";
  4.  
  5. for (int i = 0; i < pattern.Length; i += _stepSize)
  6. {
  7.         var expectedPattern = "";
  8.  
  9.         if (i + _stepSize > pattern.Length)
  10.                 expectedPattern = pattern.Substring(i, pattern.Length - i);
  11.         else
  12.                 expectedPattern = pattern.Substring(i, _stepSize);
  13.  
  14.         if (i == 0)
  15.         {
  16.                 var rulesWithCorrectPattern = DetermineRulesWithCorrectPattern(expectedPattern, _rules);
  17.  
  18.                 if (rulesWithCorrectPattern.Count != 0)
  19.                         currentRule = rulesWithCorrectPattern[_randomGenerator.Next(0, rulesWithCorrectPattern.Count)];
  20.                
  21.                 currentRule = "";
  22.         }
  23.         else
  24.         {
  25.                 var rulesWithCorrectPattern = DetermineRulesWithCorrectPattern(expectedPattern, _rules[currentRule]);
  26.  
  27.                 if (rulesWithCorrectPattern.Count != 0)
  28.                         currentRule = rulesWithCorrectPattern[_randomGenerator.Next(0, rulesWithCorrectPattern.Count)];
  29.                
  30.                 currentRule = "";
  31.         }
  32.  
  33.         if (currentRule == string.Empty)
  34.                 break;
  35.  
  36.         name += currentRule;
  37. }