Source/NFX/Parsing/NaturalTextGenerator.cs
/// <summary>
/// Generates a random English word which is of the specified size. The min size must be of at least 4 chars
/// </summary>
Generates a random English word which is of the specified size. The min size must be of at least 4 chars
Generates a random English word which is of the specified size . The min size must be of at least 4 chars
public static string GenerateWord(int minLength = 4, int maxLength = 20)
    {
      if (minLength<4) minLength = 4;
      if (maxLength<minLength) maxLength = 20;
      var text = getRandomTextSource();
      var i = NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, text.Length-1);
      scrollToWordStart(text, ref i);
      var result = new StringBuilder();
      while(true)
      {
        result.Clear();
          while(true)
          {
           if (i>=text.Length)
           {
            i=0;
            scrollToWordStart(text, ref i);
           }
           var chr = text[i];
           i++;
           if (!filter(chr)) break;
           result.Append( chr );
          }
        var len = result.Length;
        if (len>=minLength && len<=maxLength) break;
      }
      return result.ToString();
    }
public static string GenerateWord ( int minLength = 4 , int maxLength = 20 ) { if ( minLength < 4 ) minLength = 4 ; if ( maxLength < minLength ) maxLength = 20 ; var text = getRandomTextSource ( ) ; var i = NFX . ExternalRandomGenerator . Instance . NextScaledRandomInteger ( 0 , text . Length - 1 ) ; scrollToWordStart ( text , ref i ) ; var result = new StringBuilder ( ) ; while ( true ) { result . Clear ( ) ; while ( true ) { if ( i >= text . Length ) { i = 0 ; scrollToWordStart ( text , ref i ) ; } var chr = text [ i ] ; i ++ ; if ( ! filter ( chr ) ) break ; result . Append ( chr ) ; } var len = result . Length ; if ( len >= minLength && len <= maxLength ) break ; } return result . ToString ( ) ; }
Generates a random English word which is of the specified size.
Generates a random English word which is of the specified size .
minLength
int
maxLength
int