|shutting off the random generator
|topic started 9/7/2006; 11:53:24 AM
last post 9/7/2006; 3:33:42 PM
|Davide P. Cervone - Re: shutting off the random generator
9/7/2006; 3:33:42 PM (reads: 324, responses: 0)
is an alternative to John's suggestion. It is a real hack, but it would
work without modification to the system, and without having to write
scripts that need to be executed at the command line.
The idea is that you want to be able to run a small bit of code at the beginning of each problem, and that code would set the random seed to a common value across all the students in the class. The trick is to get that code executed without having to edit all the problems.
The solution (which I admit to be a horrible hack) is to realize that you already have code that is run at the beginning of each problem, namely the macro files that are loaded via loadMacros(). We will hook into one of these as a sneaky means of getting our own code to run in addition to its usual contents. We can do that by making a copy of th emacro file in our course's templates/macros directory, and modify that.
Almost all problems include PG.pl, PGbasicmacros.pl and PGanswermacros.pl, but these are actually preloaded by WeBWorK, and are not actually read for each problem, so we can't use those as our vehicle for our Trogan horse. Luckily, however, most problems also include PGauxiliaryFunctions.pl and PGchoicemacros.pl. Either of these would do.
Here's the process:
This will case the random number generator to be seeded with the same value for all students (the seed value will be the problem number, so that different problems will be seeded with different values, at least.) That means all students will get the same version of the problem, regardless of the seed assigned originally by WeBWorK.
Note, however, that this will be the case for ALL problem sets (in this one course). If you want this to be true for only ONE problem set, you could use
SRAND($probNum) if $setNumber eq 'set-name';where set-name is the name of the set that you want to be the same for every student. You could include additional lines for additional sets if you needed it for more than one.
As I said, it's a terrible hack, but it should work.
PS, Mike, here's another example of where having a blank macro file loaded by all programs would come in helpfull. If all problems included PGcourse.pl, which is by default a blank perl file, then this file could be used to customize the environment on a course-by-course or set-by-set basis like this. All Union College problems include this, but most others don't.