Documentation
    Preparing search index...
    • Extracts a random substring from the provided content string.

      Selects two random positions within the content and returns the substring between them. The starting position is always before the ending position. Automatically trims whitespace from the beginning and end of the result. Useful for creating excerpts, search terms, or partial content samples.

      Processing cost: Two draws choose the slice bounds; substring and trimming cost at most O(N) in the input length.

      Parameters

      • content: string

        The source string to extract a substring from

      Returns string

      A trimmed substring of the original content

      const text = "The quick brown fox jumps over the lazy dog";

      RandomGenerator.substring(text); // e.g. "quick brown fox"
      RandomGenerator.substring(text); // e.g. "jumps over"
      RandomGenerator.substring(text); // e.g. "fox jumps over the lazy"

      // Generate search terms from content
      const searchQuery = RandomGenerator.substring(articleContent);

      // Create excerpts for previews
      const excerpt = RandomGenerator.substring(fullBlogPost);

      // Generate partial matches for testing search functionality
      const partialMatch = RandomGenerator.substring(productDescription);

      // Create random selections for highlight testing
      const selectedText = RandomGenerator.substring(documentContent);

      contracts/common.md#principled-implementation For nonempty input, the first index is a valid position and the last is strictly later up to the length. Trimming can empty a whitespace slice. Empty input also returns an empty string; substring clamps its drawn bounds to the empty input.

      contracts/common.md#clear-and-simple-design Two draws and one slice.

      contracts/common.md#prohibited-implementation-shortcuts The slice bounds are drawn, not fixed.

      contracts/common.md#meaningful-documentation The comment states that the slice is random and trimmed, with examples.