On 3 August 2012 10:54, seldont <[email protected]> wrote:
> Just thought I'd pass this on.
>
> I've been trying to simulate an online test where users have to write a one
> word answer to each question.
>
> I wanted the response to be a random selection from several possibilities, I
> thought this would be a fairly simple thing but all the posted solutions
> seemed quite complex.
>
> In the end I came up with a simple solution using a single variable and
> regexp.
>
> I set the options in a variable with a common separator (= in the following
> example)
>
> weekday : Monday=Tuesday=Wednesday=Thursday=Friday=
>
> Then to select a random answer I used the following regexp:
>
> ${__regexFunction(([^=]*)=,$1$,RAND,,Anyday,,weekday)}
>
> The two '=' in the expression must match the separator used in the variable.
> 'Anyday' is the response if no matches exist in the specified variable (i.e.
> something has gone wrong)
> weekday is the name of the variable containing the options
>
> If you wanted a lot of choices, you could read the 'value choices' in from a
> CSV file (different choices on each line). This wouldn't give a totally
> random selection but would be more random than reading values from a CSV
> file that are in a pre-defined order.
>
> CSV example file (select one type of animal):
> Dog=Fish=Whale=,
> Cat=Monkey=Elephant=Mouse=,
> Frog=Lion=,
>
> Another use for this might be to make the variable part of a URL to go to
> one of several predefined locations.
>
> e.g. /home.html=/help.html=/products.pdf=
>
>
> Hope people find this useful
>

That approach seems fine for a small word-list, but would require lots
of storage for a large word list.

CSV can also be used with a pre-randomised word-list, which can be any
size (use one word per line).
It also allows for random order tests that must not repeat the same
entry twice (cf. shuffling a pack of cards).

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to