mindmetoo
Joined: 02 Feb 2004
|
Posted: Thu Dec 21, 2006 3:22 pm Post subject: Randomize your multiple choice questions |
|
|
This is "alpha" mode right now. I'm going to add more bells and whistles (for example, being able to randomize multiple lists at once). I'm not sure the question field is needed. Anything you think needs adding?
http://www.gokorea.info/order.htm
You'll need to enter each item on its own line. I could have it also randomize a comma or tab delimited list but typically tests don't use such lists.
You'll notice one of the stickies above I wrote some Word Macro code to let you highlight a list in your document and then randomize it. This saves you the task of writing multiple choice tests and having to manually randomize the answers. Just highlight and boom. The downside is not everyone is savvy enough to handle the macro utility to paste in this code and it doesn't work on Mac Word. So I'm implementing it in PHP and in the process teaching myself PHP. Three days ago I was trying to figure out how to use ECHO so my code is pretty crappy.
If anyone knows PHP, here is the code below. (Quantity should be list_to_randomize or something.... some cut 'n' paste code I used from a PHP ordering form...)
Code: |
<?php
$question = $_POST['question'];
$quantity = $_POST['quantity'];
$aletterflag = $_POST['autoletter'];
$auto_let_array = array('a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
't', 'u', 'v', 'w', 'x', 'y', 'z', 'aa', 'bb', 'cc', 'dd',
'ee', 'ff', 'gg', 'hh', 'ii', 'jj', 'kk', 'll', 'mm', 'nn',
'oo', 'pp', 'qq', 'rr', 'ss' ,'tt', 'uu', 'vv', 'ww', 'xx',
'yy', 'zz');
$quantityb = split("\r", $quantity);
// get the number of items in the array
// array starts at zero so remember a 3 item count is 0 1 2
$aarraycount = count($quantityb);
// get the last item in the array
$lastitem = strlen($quantityb[$aarraycount-1]);
// trim a blank line
if ($lastitem == 1)
{
$quantityb = array_slice($quantityb, 0, $aarraycount-1);
}
$aarraycount = count($quantityb);
$aarraycount--;
srand(time());
shuffle($quantityb);
shuffle($quantityb);
shuffle($quantityb);
echo $question . '<p>';
// $aletterflag checkbox to auto letter the list
if ($aletterflag == "on")
{
for ($i = 0; $i <= $aarraycount; $i++)
{
echo $auto_let_array[$i] . '. ' . $quantityb
[$i].'<br>';
}
}
else
{
echo '<br>';
for ($i = 0; $i <= $aarraycount; $i++)
{
echo $quantityb[$i].'<br>';
}
}
?> |
I generate the auto lettering with an array vs using HTML's <OL type="a"> tag because when you cut 'n' paste from the output and don't highlight and copy the invisible OL tag, Word doesn't keep the lettering and just reads the <li> tags and renders it as bullets.
I was amused to find a shuffle() function in PHP, which saved me a whack of code. |
|