createSentence static method
Creates random sentences.
Sentences are either exactly sentenceLength
words in length, or a randomly
generated length. numSentences
defines the number of sentences generated.
Returned sentences are punctuated.
Implementation
static String createSentence(
{int sentenceLength = -1, int numSentences = 1}) {
int wordIndex;
String sentence;
if (numSentences > 1) return createParagraph(numSentences: numSentences);
if (sentenceLength < 0) {
sentenceLength = _randomInt(5, 20);
}
wordIndex = _randomInt(0, words.length - sentenceLength - 1);
sentence = words.getRange(wordIndex, wordIndex + sentenceLength).join(" ");
sentence = "${sentence[0].toUpperCase()}${sentence.substring(1)}.";
return sentence;
}