Skip to content

Instantly share code, notes, and snippets.

@baileylo
Created July 21, 2016 00:29
Show Gist options
  • Save baileylo/54b4df4f5b310e8be25ca92270b4400b to your computer and use it in GitHub Desktop.
Save baileylo/54b4df4f5b310e8be25ca92270b4400b to your computer and use it in GitHub Desktop.
A speech writer designed to prevent plagiarism
<?php
if ($argc < 2) {
echo "Please enter a number of words for the speech\n";
exit(1);
}
$dictionary = explode(PHP_EOL, `cat /usr/share/dict/words`);
$speech = [];
$max_words = (int)$argv[1];
for($word_count = 1; $word_count <= $max_words; $word_count++) {
$word = $dictionary[random_int(0, count($dictionary))];
// Try to make sentences around 6 words long
$speech[] = $word . (random_int(0, 5) < 1 ? '.' : '');
}
echo implode(' ', $speech) . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment