[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm

raeburn raeburn at source.lon-capa.org
Wed Nov 6 21:58:38 EST 2019


raeburn		Thu Nov  7 02:58:38 2019 EDT

  Modified files:              
    /loncom/homework	structuretags.pm 
  Log:
  - Bug 6919.  In multi-part problems with type=randomizetry for some (but not 
    all) parts, first call to &random() in script block in a part sets seed if 
    type=randomizetry for current part, or if type=randomizetry for previous
    part, but not current part.
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.569 loncom/homework/structuretags.pm:1.570
--- loncom/homework/structuretags.pm:1.569	Wed Nov  6 16:20:06 2019
+++ loncom/homework/structuretags.pm	Thu Nov  7 02:58:37 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.569 2019/11/06 16:20:06 raeburn Exp $
+# $Id: structuretags.pm,v 1.570 2019/11/07 02:58:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -667,7 +667,7 @@
 }
 
 sub setup_rndseed {
-    my ($safeeval,$target,$probpartlist)=@_;
+    my ($safeeval,$target,$probpartlist,$prevparttype)=@_;
     my ($symb)=&Apache::lonnet::whichuser();
     my ($questiontype,$set_safespace,$rndseed,$numtries,$reqtries);
     if ($target eq 'analyze') {
@@ -784,15 +784,16 @@
         if ($target eq 'grade') {
             $Apache::lonhomework::rawrndseed = $rndseed;
         }
+    } elsif ($prevparttype eq 'randomizetry') {
+        if ($env{'form.0.rndseed'} ne '') {
+            $set_safespace = 1;
+            $rndseed = $env{'form.0.rndseed'};
+        }
     }
     if ($set_safespace) {
         if ($safeeval) {
             &Apache::lonxml::debug("Setting rndseed to $rndseed");
             &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval);
-            my $prevparttype;
-            if (@Apache::inputtags::partlist > 1) {
-                $prevparttype = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[-2].type");
-            }
             if (($Apache::lonhomework::type eq 'randomizetry') || ($prevparttype eq 'randomizetry')) {
                 &Apache::lonxml::debug("Setting randomizetrypart to $Apache::inputtags::part");
                 &Apache::run::run('$external::randomizetrypart="'.$Apache::inputtags::part.'";',$safeeval);
@@ -1908,7 +1909,7 @@
                 $form_tag_start.=&practice_problem_header();
             }
 	    $form_tag_start.='<hr />';
-        } 
+        }
         if (($env{'request.state'} ne "construct") &&
             ($Apache::lonhomework::type eq 'randomizetry') &&
             ($status eq 'CAN_ANSWER') &&
@@ -2958,6 +2959,14 @@
         if (($target eq 'grade') && &Apache::response::submitted()) {
             $Apache::lonhomework::results{"resource.$id.rndseed"}=$rndseed;
         }
+    } elsif (@Apache::inputtags::partlist > 1) {
+        my $prevparttype = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[-2].type");
+        if ($prevparttype eq 'randomizetry') {
+            my $rndseed=&setup_rndseed($safeeval,$target,'',$prevparttype);
+            if (($target eq 'grade') && &Apache::response::submitted()) {
+                $Apache::lonhomework::results{"resource.$id.rndseed"}=$rndseed;
+            }
+        }
     } elsif (($target eq 'grade') && &Apache::response::submitted()) {
         $Apache::lonhomework::results{"resource.$id.rndseed"}=$Apache::lonhomework::rawrndseed;
     }
@@ -3394,7 +3403,7 @@
     my ($header,$text);
     if ($reqtries eq 'none') {
         $header = &mt('No Question Variation');
-        $text = &mt('For this question there will no new variation after a try.');
+        $text = &mt('For this question there will be no new variation after a try.');
     } elsif ($reqtries > 1) {
         $header = &mt('New Question Variation After Every [quant,_1,Try,Tries]',$reqtries);
         if (($problemstatus eq 'no') ||




More information about the LON-CAPA-cvs mailing list