Source/NFX/Parsing/NaturalTextGenerator.cs
/// <summary>
/// Generates human-readable English text of up to specified length which is of 10 chars at minimum.
/// If zero passed then generates msg of random length
/// </summary>
Generates human-readable English text of up to specified length which is of 10 chars at minimum.
If zero passed then generates msg of random length
Generates human - readable English text of up to specified length which is of 10 chars at minimum . If zero passed then generates msg of random length
public static string Generate(int length = 150)
    {
      if (length<=0) length = 15 + NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 135);
      if (length<10) length = 10;
      var text = getRandomTextSource();
      var i = NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, text.Length-1);
      scrollToWordStart(text, ref i);
      var result = new StringBuilder();
      var skipping = false;
      var lengthAfterLastWord = 0;
      while(true)
      {
       if (i>=text.Length)
       {
        i=0;
        scrollToWordStart(text, ref i);
       }
       var chr = text[i];
       i++;
       if (!filter(chr))
       {
         if (result.Length >= length) break;
         if (!skipping)
         {
          lengthAfterLastWord = result.Length;
         }
         skipping = true;
         continue;
       }
       if (skipping) result.Append(' ');
       skipping = false;
       result.Append( chr );
      }
      if (result.Length > length) result.Length = lengthAfterLastWord;
      return result.ToString();
    }
public static string Generate ( int length = 150 ) { if ( length <= 0 ) length = 15 + NFX . ExternalRandomGenerator . Instance . NextScaledRandomInteger ( 0 , 135 ) ; if ( length < 10 ) length = 10 ; var text = getRandomTextSource ( ) ; var i = NFX . ExternalRandomGenerator . Instance . NextScaledRandomInteger ( 0 , text . Length - 1 ) ; scrollToWordStart ( text , ref i ) ; var result = new StringBuilder ( ) ; var skipping = false ; var lengthAfterLastWord = 0 ; while ( true ) { if ( i >= text . Length ) { i = 0 ; scrollToWordStart ( text , ref i ) ; } var chr = text [ i ] ; i ++ ; if ( ! filter ( chr ) ) { if ( result . Length >= length ) break ; if ( ! skipping ) { lengthAfterLastWord = result . Length ; } skipping = true ; continue ; } if ( skipping ) result . Append ( ' ' ) ; skipping = false ; result . Append ( chr ) ; } if ( result . Length > length ) result . Length = lengthAfterLastWord ; return result . ToString ( ) ; }
Generates human-readable English text of up to specified length which is of 10 chars at minimum.
Generates human - readable English text of up to specified length which is of 10 chars at minimum .
length
int