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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 27 Feb 2003 22:20:40 -0000


albertel		Thu Feb 27 17:20:40 2003 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - modified random answer gerartion to use new better generator
  - no longer always get C as the correct answer
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.79 loncom/homework/caparesponse/caparesponse.pm:1.80
--- loncom/homework/caparesponse/caparesponse.pm:1.79	Thu Feb 27 16:20:33 2003
+++ loncom/homework/caparesponse/caparesponse.pm	Thu Feb 27 17:20:40 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.79 2003/02/27 21:20:33 sakharuk Exp $
+# $Id: caparesponse.pm,v 1.80 2003/02/27 22:20:40 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -144,7 +144,7 @@
 	$response =~ s/\'/\\\'/g;
 	&Apache::lonxml::debug("current $response");
 	my $expression="&caparesponse_check_list('".$response."','".
-	  $$parstack[$#$parstack];
+	    $$parstack[-1];
 	foreach my $key (keys(%Apache::inputtags::params)) {
 	  $expression.= ';my $'. #'
 	    $key.'="'.$Apache::inputtags::params{$key}.'"';
@@ -223,15 +223,15 @@
 	my $powers_number = 8; #default values for number of powers
 	my $symb;
 	if ($ENV{'form.symb'}=~/___\d+___/) {$symb=$ENV{'form.symb'};} else {$symb=$ENV{'request.symb'};}
-	srand(&Apache::lonnet::rndseed($symb,$ENV{'request.course.id'},
-                                                              $ENV{'user.domain'},$ENV{'user.name'}));
-	my $ind=1+int(rand()*($factors_number-1));
-	my $factor = $factors[$ind];
-	$ind=1+int(rand()*($powers_number-1));
+
+	&Apache::response::setrandomnumber();
+	my $ind=&Math::Random::random_uniform_integer(1,0,$#powers);
 	my $power = $powers[$ind];
+	$ind=&Math::Random::random_uniform_integer(1,0,$#factors);
+	my $factor = $factors[$ind];
 	for ($ind=0;$ind<$number_of_bubbles;$ind++) {
-	    $bubbles_values[$ind] = $answers[0]*$factor**($power-$powers[$powers_number-$ind-1]);
-	}	    
+	    $bubbles_values[$ind] = $answers[0]*($factor**($power-$powers[$#powers-$ind]));
+	}
 	my @alphabet = ('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');
         if ($target eq 'web') {