[OT] programming question

Nicholas Clark nick at ccl4.org
Wed Apr 25 23:26:57 BST 2007


Say I'm trying to write a web based quiz. Multiple guess.
What I think I want to do is have my backend take the list of possible answers
and display them in random order. My HTML form has $n radio buttons, with $n
form parameter options, and (obviously) only one is correct.

Now, the simplest way I can see of saving state long term is to have it so
that the master file of questions has answers in fixed order, so that one
maps the radio option chosen back to the fixed location of that answer.
And the simplest way of knowing the correct answer is to have it first in
the unrandomised order. Only, here we have an information leakage problem,
because something like

    <p>What colour should the bikeshed be?</p>
    <input type="hidden" name="question" value="42">
    <input type="radio" name="guess" value="5">Brown
    <input type="radio" name="guess" value="3">Green
    <input type="radio" name="guess" value="1">Orange
    <input type="radio" name="guess" value="4">Blue
    <input type="radio" name="guess" value="2">Black

fairly quickly gives the game away that the answer with value 1 is always
correct.

And I don't really want to maintain state on the server between generating
the question/answer order, and processing the response.

So what's the best way to randomly permute the order of the answers, store
a small amount of state in a hidden field in the form, and reproduce the
permutation back on the next call to the server, such that it can map back
to the original answer order, without (too much) information leakage?

nicholas Clark


More information about the london.pm mailing list