コード例 #1
0
ファイル: PigLatin.cs プロジェクト: t-h-e/HeuristicLab.CFGGP
 private IEnumerable <string> GetLetterStrings(int n, FastRandom rand)
 {
     for (int i = 0; i < n; i++)
     {
         var value = StringValueGenerator.GetRandomLowerCaseString(rand.Next(3, 50 + 1), rand).ToCharArray();
         for (int j = 0; j < value.Length; j++) // randomly add spaces with 20% probability at each position
         {
             if (rand.NextDouble() < 0.2)
             {
                 value[j] = ' ';
             }
         }
         string valueString = new String(value);
         yield return(String.Join(" ", valueString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))); // remove double spaces and spaces in the beginnig and the end of the string
     }
 }
コード例 #2
0
 private IEnumerable <List <string> > GetCloseOrSuperAnagrams(int n, FastRandom rand)
 {
     // string with only letters! no other symbols
     for (int i = 0; i < n; i++)
     {
         int    length = rand.Next(1, 20 + 1);
         string value0 = StringValueGenerator.GetRandomLowerCaseString(length, rand);
         string value1 = ReplaceDropCharsAndShuffle(value0, rand);
         yield return(rand.NextDouble() < 0.2 // bias towards value1 first, since value0.Length >= value1.Length
           ? new List <string>()
         {
             value0, value1
         }
           : new List <string>()
         {
             value1, value0
         });
     }
 }