Diff for /loncom/homework/response.pm between versions 1.77 and 1.78

version 1.77, 2003/05/14 13:33:00 version 1.78, 2003/05/16 20:16:18
Line 469  sub scored_response { Line 469  sub scored_response {
     return $repetition;      return $repetition;
 }  }
   
   sub whichorder {
       my ($max,$randomize,$showall,$hash)=@_;
       #&Apache::lonxml::debug("man $max randomize $randomize");
       if (!defined(@{ $$hash{'names'} })) { return; }
       my @names = @{ $$hash{'names'} };
       my @whichopt =();
       my (%top,@toplist,%bottom,@bottomlist);
       if (!($showall || ($randomize eq 'no'))) {
    my $current=0;
    foreach my $name (@names) {
       $current++;
       if ($$hash{"$name.location"} eq 'top') {
    $top{$name}=$current;
       } elsif ($$hash{"$name.location"} eq 'bottom') {
    $bottom{$name}=$current;
       }
    }
       }
       my $topcount=0;
       my $bottomcount=0;
       while (((scalar(@whichopt)+$topcount+$bottomcount) < $max || $showall)
      && ($#names > -1)) {
    #&Apache::lonxml::debug("Have $#whichopt max is $max");
    my $aopt;
    if ($showall || ($randomize eq 'no')) {
       $aopt=0;
    } else {
       $aopt=int(&Math::Random::random_uniform() * ($#names+1));
    }
    #&Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt");
    $aopt=splice(@names,$aopt,1);
    #&Apache::lonxml::debug("Picked $aopt");
    if ($top{$aopt}) {
       $toplist[$top{$aopt}]=$aopt;
       $topcount++;
    } elsif ($bottom{$aopt}) {
       $bottomlist[$bottom{$aopt}]=$aopt;
       $bottomcount++;
    } else {
       push (@whichopt,$aopt);
    }
       }
       for (my $i=0;$i<=$#toplist;$i++) {
    if ($toplist[$i]) { unshift(@whichopt,$toplist[$i]) }
       }
       for (my $i=0;$i<=$#bottomlist;$i++) {
    if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) }
       }
   
       return @whichopt;
   }
   
 1;  1;
 __END__  __END__
     

Removed from v.1.77  
changed lines
  Added in v.1.78


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>