Hi Dan,
Ok, so the length of the seed does seem to matter. The following
problem file seems to work. Note that the discussion board software
might hide or get rid of backslashes or other special characters, so
proofread it for omissions of that sort.
(Note that you only want one SRAND function call. If you call
SRAND with the same seed at the beginning of every problem in a set
you'll find the random numbers that are showing up in each problem are
the same. This is because once the seed is fixed the pseudorandom
numbers are algorithmically determined. In this case we're using the
session key for the seed, and the session key is unique to the login
session, not to every problem.)
Gavin
##DESCRIPTION ## Sample random seed problem ## ##ENDDESCRIPTION
DOCUMENT();
loadMacros( PG.pl, PGbasicmacros.pl, PGchoicemacros.pl, PGanswermacros.pl, PGauxiliaryFunctions.pl );
TEXT(&beginproblem); $showPartialCorrectAnswers = 1;
$sessionKey = $envir{'inputs_ref'}->{'key'}; # grab the key $sessionKey =~ s/[^~~w~~d]//g; # delete non alphanumerics $sessionKey =~ tr/[A-Z]/[a-z]/; # lowercase all letters $sessionKey =~ tr/[a-z]/[0-90-90-5]/; # turn a into 0, b into 1... $sessionKey = substr($sessionKey,0,4); # just take the first four # digits SRAND($sessionKey);
$a = random(1,10,1);
BEGIN_TEXT $PAR $BBOLD Math Sample Homework $EBOLD $PAR
The seed used this time is$BR $sessionKey
$PAR
A random variable is $BR $a
$PAR
Enter the number 1: \{ ans_rule(3) \}
END_TEXT
ANS( num_cmp(1) );
ENDDOCUMENT();
<| Post or View Comments |>
|