A line of iambic pentameter has a set structure. It is 10 syllables that alternate an un-stressed syllable with a stressed syllable. It shouldn't be difficult to generate a random line of iambic pentameter from a database. Assume that the database contains the following information: word, begining_stress, ending_stress, number_of_syllables.
The code to generate a single line of random iambic pentameter should look something like this:
$remaining_syllables = 10;
$ending_stress_of_line = "stressed"
while $remaining_syllables > 10 {
SELECT random($word) from database WHERE $number_of_syllables <= $remaining_syllables AND $begining_stress <> $ending_stress_of_line;
$remaining_syllables = $remaining_syllables - $syllables;
$ending_stress_of_line = $ending_stress;
$line=$line.$word;
}
Print $line;
?>
I would love any feedback on the viability of this little script or help in correctly formatting the code.