[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm optionresponse.pm radiobuttonresponse.pm response.pm structuretags.pm /lonnet/perl lonnet.pm /xml lonxml.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 27 May 2004 04:25:13 -0000
This is a MIME encoded message
--albertel1085631913
Content-Type: text/plain
albertel Thu May 27 00:25:13 2004 EDT
Modified files:
/loncom/lonnet/perl lonnet.pm
/loncom/homework default_homework.lcpm optionresponse.pm
radiobuttonresponse.pm response.pm
structuretags.pm
/loncom/xml lonxml.pm
Log:
- fixes for randnumber generation
- due to a error in coding the 64bit and 64bit2 rnd seeds were throwing away the second half of the seed, we now preserve this functionality and make it explicit
- additionally 64bit3 now uses all 64bits of the seed
- also added new function pushrandomnumber poprandomnumber to be called instead of setrandomnumber before we were crunching the Safe space random number generator state, as this function is used bu thing the <optionresponse> and <radoibuttonresponse> this meant changes in the internal randomization code could screw up later Safe space random calls the old method is preserved for blank 64bit and 64bit2 randomiztion env.
--albertel1085631913
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040527002513.txt"
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.502 loncom/lonnet/perl/lonnet.pm:1.503
--- loncom/lonnet/perl/lonnet.pm:1.502 Wed May 19 13:13:39 2004
+++ loncom/lonnet/perl/lonnet.pm Thu May 27 00:25:12 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.502 2004/05/19 17:13:39 matthew Exp $
+# $Id: lonnet.pm,v 1.503 2004/05/27 04:25:12 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -4465,6 +4465,15 @@
return '64bit3';
}
+sub get_rand_alg {
+ my ($courseid)=@_;
+ if (!$courseid) { $courseid=(&Apache::lonxml::whichuser())[1]; }
+ if ($courseid) {
+ return $ENV{"course.$courseid.rndseed"};
+ }
+ return &latest_rnd_algorithm_id();
+}
+
sub getCODE {
if (defined($ENV{'form.CODE'})) { return $ENV{'form.CODE'}; }
if (defined($Apache::lonhomework::parsing_a_problem) &&
@@ -4484,7 +4493,7 @@
if (!$courseid) { $courseid=$wcourseid; }
if (!$domain) { $domain=$wdomain; }
if (!$username) { $username=$wusername }
- my $which=$ENV{"course.$courseid.rndseed"};
+ my $which=&get_rand_alg();
if (defined(&getCODE())) {
return &rndseed_CODE_64bit($symb,$courseid,$domain,$username);
} elsif ($which eq '64bit3') {
@@ -4574,7 +4583,7 @@
my $num2=$nameseed+$domainseed+$courseseed;
#&Apache::lonxml::debug("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck");
#&Apache::lonxml::debug("rndseed :$num:$symb");
- return "$num1,$num2";
+ return "$num1:$num2";
}
}
@@ -4591,14 +4600,14 @@
my $num2=$CODEseed+$courseseed+$symbchck;
#&Apache::lonxml::debug("$symbseed:$CODEchck|$CODEseed:$courseseed:$symbchck");
#&Apache::lonxml::debug("rndseed :$num1:$num2:$symb");
- return "$num1,$num2";
+ return "$num1:$num2";
}
}
sub setup_random_from_rndseed {
my ($rndseed)=@_;
- if ($rndseed =~/,/) {
- my ($num1,$num2)=split(/,/,$rndseed);
+ if ($rndseed =~/([,:])/) {
+ my ($num1,$num2)=split(/[,:]/,$rndseed);
&Math::Random::random_set_seed(abs($num1),abs($num2));
} else {
&Math::Random::random_set_seed_from_phrase($rndseed);
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.83 loncom/homework/default_homework.lcpm:1.84
--- loncom/homework/default_homework.lcpm:1.83 Wed May 26 23:46:02 2004
+++ loncom/homework/default_homework.lcpm Thu May 27 00:25:13 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
#
-# $Id: default_homework.lcpm,v 1.83 2004/05/27 03:46:02 albertel Exp $
+# $Id: default_homework.lcpm,v 1.84 2004/05/27 04:25:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -242,7 +242,10 @@
if ( ! $hidden::RANDOMINIT ) {
if ($external::randomseed == 0) { $external::randomseed=1; }
if ($external::randomseed =~/,/) {
- my ($num1,$num2)=split(/,/,$seed);
+ my ($num1,$num2)=split(/,/,$external::randomseed);
+ &random_set_seed(1,abs($num1));
+ } elsif ($external::randomseed =~/:/) {
+ my ($num1,$num2)=split(/:/,$external::randomseed);
&random_set_seed(abs($num1),abs($num2));
} else {
&random_set_seed(1,int(abs($external::randomseed)));
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.109 loncom/homework/optionresponse.pm:1.110
--- loncom/homework/optionresponse.pm:1.109 Thu May 6 03:31:32 2004
+++ loncom/homework/optionresponse.pm Thu May 27 00:25:13 2004
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.109 2004/05/06 07:31:32 albertel Exp $
+# $Id: optionresponse.pm,v 1.110 2004/05/27 04:25:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -92,7 +92,7 @@
my $result='';
%Apache::response::foilgroup=();
$Apache::optionresponse::conceptgroup=0;
- &Apache::response::setrandomnumber();
+ &Apache::response::pushrandomnumber();
if ($target eq 'edit') {
my $optionlist="<option></option>\n";
my $option;
@@ -257,6 +257,7 @@
if ($target eq 'tex' and $Apache::lonhomework::type ne 'exam') {
$result .= '\end{enumerate}';
}
+ &Apache::response::poprandomnumber();
return $result;
}
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.88 loncom/homework/radiobuttonresponse.pm:1.89
--- loncom/homework/radiobuttonresponse.pm:1.88 Fri May 7 13:18:45 2004
+++ loncom/homework/radiobuttonresponse.pm Thu May 27 00:25:13 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# mutliple choice style responses
#
-# $Id: radiobuttonresponse.pm,v 1.88 2004/05/07 17:18:45 albertel Exp $
+# $Id: radiobuttonresponse.pm,v 1.89 2004/05/27 04:25:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -106,7 +106,7 @@
my $result;
%Apache::response::foilgroup=();
$Apache::radiobuttonresponse::conceptgroup=0;
- &Apache::response::setrandomnumber();
+ &Apache::response::pushrandomnumber();
if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
$result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
}
@@ -197,6 +197,7 @@
}
}
}
+ &Apache::response::poprandomnumber();
&Apache::lonxml::increment_counter();
return $result;
}
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.98 loncom/homework/response.pm:1.99
--- loncom/homework/response.pm:1.98 Fri May 7 13:20:19 2004
+++ loncom/homework/response.pm Thu May 27 00:25:13 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# various response type definitons response definition
#
-# $Id: response.pm,v 1.98 2004/05/07 17:20:19 albertel Exp $
+# $Id: response.pm,v 1.99 2004/05/27 04:25:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -84,27 +84,59 @@
return '';
}
-# used by response to set the non-safe space random number generator to something
-# that is stable and unique based on the part number and response number
+my @randomseeds;
+sub pushrandomnumber {
+ my $rand_alg=&Apache::lonnet::get_rand_alg();
+ if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
+ $rand_alg eq '64bit2') {
+ # do nothing
+ } else {
+ my @seed=&Math::Random::random_get_seed();
+ push (@randomseeds,\@seed);
+ }
+ &Apache::response::setrandomnumber();
+}
+sub poprandomnumber {
+ my $rand_alg=&Apache::lonnet::get_rand_alg();
+ if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
+ $rand_alg eq '64bit2') {
+ return;
+ }
+ my $seed=pop(@randomseeds);
+ if ($seed) {
+ &Math::Random::random_set_seed(@$seed);
+ } else {
+ &Apache::lonxml::error("Unable to restore random algorithm.");
+ }
+}
sub setrandomnumber {
my $rndseed;
$rndseed=&Apache::structuretags::setup_rndseed();
if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); }
&Apache::lonxml::debug("randseed $rndseed");
# $rndseed=unpack("%32i",$rndseed);
- my $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10);
- if (defined($Apache::inputtags::response['-1'])) {
- $rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]);
- }
- if ($rndseed =~/,/) {
- {
- use integer;
- my ($num1,$num2)=split(/,/,$rndseed);
- $num1+=$rndmod;
- $num2+=$rndmod;
- $rndseed="$num1,$num2";
+ my $rand_alg=&Apache::lonnet::get_rand_alg();
+ my $rndmod;
+ if (!$rand_alg || $rand_alg eq '32bit' || $rand_alg eq '64bit' ||
+ $rand_alg eq '64bit2') {
+ $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10);
+ if (defined($Apache::inputtags::response[-1])) {
+ $rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]);
}
} else {
+ $rndmod=(&Apache::lonnet::numval2($Apache::inputtags::part) << 10);
+ if (defined($Apache::inputtags::response[-1])) {
+ $rndmod+=&Apache::lonnet::numval2($Apache::inputtags::response[-1]);
+ }
+ }
+ if ($rndseed =~/([,:])/) {
+ my $char=$1;
+ use integer;
+ my ($num1,$num2)=split(/\Q$char\E/,$rndseed);
+ $num1+=$rndmod;
+ $num2+=$rndmod;
+ $rndseed=$num1.$char.$num2;
+ } else {
$rndseed+=$rndmod;
}
&Apache::lonnet::setup_random_from_rndseed($rndseed);
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.249 loncom/homework/structuretags.pm:1.250
--- loncom/homework/structuretags.pm:1.249 Thu May 20 19:11:12 2004
+++ loncom/homework/structuretags.pm Thu May 27 00:25:13 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.249 2004/05/20 23:11:12 albertel Exp $
+# $Id: structuretags.pm,v 1.250 2004/05/27 04:25:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -178,7 +178,7 @@
}
if ($safeeval) {
&Apache::lonxml::debug("Setting rndseed to $rndseed");
- &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval);
+ &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval);
}
}
return $rndseed;
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.318 loncom/xml/lonxml.pm:1.319
--- loncom/xml/lonxml.pm:1.318 Fri May 21 17:07:54 2004
+++ loncom/xml/lonxml.pm Thu May 27 00:25:13 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.318 2004/05/21 21:07:54 matthew Exp $
+# $Id: lonxml.pm,v 1.319 2004/05/27 04:25:13 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -743,7 +743,7 @@
my $rndseed;
my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
$rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name);
- $safeinit .= ';$external::randomseed='.$rndseed.';';
+ $safeinit .= ';$external::randomseed="'.$rndseed.'";';
&Apache::lonxml::debug("Setting rndseed to $rndseed");
&Apache::run::run($safeinit,$safeeval);
--albertel1085631913--