On Sat, Sep 15, 2012 at 4:46 PM, <jmrhide-p...@yahoo.com> wrote: > The user clicks on a button ("A" or "B"), which fires back a string that > reawakens the script and shows it what answer the user chose. The script > inspects the cooky-jar to determine the state of the script, compares the > user's selection with its expectation, and fires back one of two new web > pages. > If the user chose the right answer, he gets congratulations and a new > problem. > If it was a wrong answer, he gets a correction, which includes the correct > term, definition, vignette, and a sound-file with pronunciation of the > term. > Then the user has to click to continue the tutorial. That click sends a > string > that re-awakens the script and cues it to send a new question. >
I assume from this description that the "while" loops are picking terms at random, and you don't want to repeat a term in the same question. I noticed several loops that use "int( rand( 5 ) )" to get 3 unique numbers. Since "rand" returns decimals, it's plausible that the loop can't find three unique integers. For example, "rand" keeps returning decimal numbers between 3 and 4, like 3.4526180 and 3.9876261 and 3.1182304. Instead of picking answers at random, what about shuffling the answers and take the top 5? They're still in a random order. And you eliminate even the possibility of an infinite loop. A module like Array::Shuffle ( http://search.cpan.org/~salva/Array-Shuffle-0.03/lib/Array/Shuffle.pm) should work nicely. -- Robert Wohlfarth