version 1.73, 2003/04/30 21:19:13
|
version 1.78, 2003/05/16 20:16:18
|
Line 83 sub setrandomnumber {
|
Line 83 sub setrandomnumber {
|
$rndseed=$ENV{'form.rndseed'}; |
$rndseed=$ENV{'form.rndseed'}; |
if (!$rndseed) { $rndseed=time; } |
if (!$rndseed) { $rndseed=time; } |
} else { |
} else { |
my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); |
$rndseed=&Apache::lonnet::rndseed(); |
$rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name); |
|
} |
} |
&Apache::lonxml::debug("randseed $rndseed"); |
&Apache::lonxml::debug("randseed $rndseed"); |
# $rndseed=unpack("%32i",$rndseed); |
# $rndseed=unpack("%32i",$rndseed); |
$rndseed=$rndseed |
my $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10); |
+(&Apache::lonnet::numval($Apache::inputtags::part) << 10); |
|
if (defined($Apache::inputtags::response['-1'])) { |
if (defined($Apache::inputtags::response['-1'])) { |
$rndseed=$rndseed |
$rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]); |
+&Apache::lonnet::numval($Apache::inputtags::response['-1']); |
|
} |
} |
&Math::Random::random_set_seed_from_phrase($rndseed); |
if ($rndseed =~/,/) { |
|
my ($num1,$num2)=split(/,/,$rndseed); |
|
$num1+=$rndmod; |
|
$num2+=$rndmod; |
|
$rndseed="$num1,$num2"; |
|
} else { |
|
$rndseed+=$rndmod; |
|
} |
|
&Apache::lonnet::setup_random_from_rndseed($rndseed); |
&Apache::lonxml::debug("randseed $rndseed"); |
&Apache::lonxml::debug("randseed $rndseed"); |
return ''; |
return ''; |
} |
} |
Line 358 sub setup_params {
|
Line 363 sub setup_params {
|
sub answer_header { |
sub answer_header { |
my ($type) = @_; |
my ($type) = @_; |
my $result; |
my $result; |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse' ) { |
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
$result = '<table border="1"><tr><th>Answer for Part:'. |
$result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: '. |
$Apache::inputtags::part. '</th></tr><tr>'."\n"; |
$Apache::inputtags::part.' \\\\ \hline '; |
} else { |
} else { |
$result = '<table border="1"><tr><td>Answer for Part:'. |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse' ) { |
$Apache::inputtags::part. '</td>'."\n"; |
$result = '<table border="1"><tr><th>Answer for Part:'. |
|
$Apache::inputtags::part. '</th></tr><tr>'."\n"; |
|
} else { |
|
$result = '<table border="1"><tr><td>Answer for Part:'. |
|
$Apache::inputtags::part. '</td>'."\n"; |
|
} |
} |
} |
return $result; |
return $result; |
} |
} |
Line 371 sub answer_header {
|
Line 381 sub answer_header {
|
sub answer_part { |
sub answer_part { |
my ($type,$answer) = @_; |
my ($type,$answer) = @_; |
my $result; |
my $result; |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { |
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
$result = '<td>'.$answer.'</td>'; |
$result = ' '.$answer.'\\\\ \hline '; |
} else { |
} else { |
$result = '<td>'.$answer.'</td>'; |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { |
|
$result = '<td>'.$answer.'</td>'; |
|
} else { |
|
$result = '<td>'.$answer.'</td>'; |
|
} |
} |
} |
return $result; |
return $result; |
} |
} |
Line 382 sub answer_part {
|
Line 396 sub answer_part {
|
sub answer_footer { |
sub answer_footer { |
my ($type) = @_; |
my ($type) = @_; |
my $result; |
my $result; |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { |
if ($ENV{'form.answer_output_mode'} eq 'tex') { |
$result = '</tr></table>'; |
$result = ' \end{tabular} \vskip 0 mm '; |
} else { |
} else { |
$result = '</tr></table>'; |
if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { |
|
$result = '</tr></table>'; |
|
} else { |
|
$result = '</tr></table>'; |
|
} |
} |
} |
return $result; |
return $result; |
} |
} |
Line 451 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__ |
|
|