--- loncom/homework/default_homework.lcpm 2003/03/25 23:00:18 1.59 +++ loncom/homework/default_homework.lcpm 2003/06/07 03:52:39 1.63 @@ -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.59 2003/03/25 23:00:18 albertel Exp $ +# $Id: default_homework.lcpm,v 1.63 2003/06/07 03:52:39 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -62,6 +62,8 @@ sub caparesponse_check { $message .="no ws in :$response:\n"; } + if (length($response) > 500) { return "TOO_LONG: Answer too long"; } + if ($type eq '' ) { $message .= "Didn't find a type :$type:$expr: defaulting\n"; if ( $answer eq ($answer *1.0)) { $type = 2; @@ -82,7 +84,7 @@ sub caparesponse_check { #formula type setup the sample points if ($type eq '8') { ($id_list,$points)=split(/@/,$samples); - $message.="Found :$points: points\n"; + $message.="Found :$id_list:$points: points in $samples\n"; } if ($tol eq '') { $tol=0.0; @@ -134,7 +136,7 @@ sub get_array_args { my ($expr,$arg)=@_; # do these first, because who knows what varname the instructor might have used # but it probably isn't $CAPARESPONSE_CHECK_LIST_answer - my $CAPARESPONSE_CHECK_LIST_answer = eval $expr.';return $'.$arg; #' + my $CAPARESPONSE_CHECK_LIST_answer = eval $expr.';return $'.$arg; #' stupid emacs my $GET_ARRAY_ARGS_result; my @GET_ARRAY_ARGS_list; if ($CAPARESPONSE_CHECK_LIST_answer =~ /^\s*[\$\@]/) { @@ -142,7 +144,7 @@ sub get_array_args { } $GET_ARRAY_ARGS_result.="error:$@:\n"; # if the eval fails just use what is in the answer exactly - if (!defined(@GET_ARRAY_ARGS_list) || !defined($GET_ARRAY_ARGS_list[0])) { + if (!(@GET_ARRAY_ARGS_list) || !defined($GET_ARRAY_ARGS_list[0])) { $GET_ARRAY_ARGS_result.="list zero is undefined\n"; $GET_ARRAY_ARGS_list[0]=$CAPARESPONSE_CHECK_LIST_answer; } @@ -151,10 +153,11 @@ sub get_array_args { sub caparesponse_check_list { my ($response,$expr)=@_; - my $result; $expr =~ s/\\/\\\\/g; $expr =~ s/\'/\\\'/g; my ($result,@list) = &get_array_args($expr,'answer'); + $expr =~ s/\\\'/\'/g; + $expr =~ s/\\\\/\\/g; my $aresult=''; my $current_answer; my $answers=join(':',@list); @@ -239,17 +242,22 @@ sub hinton { } sub random { - my ($start,$end,$step)=@_; - if ( ! $hidden::RANDOMINIT ) { - if ($external::randomseed == 0) { $external::randomseed=1; } - &random_set_seed(1,int(abs($external::randomseed))); - &math_random_uniform(); - $hidden::RANDOMINIT=1; - } - if (!defined($step)) { $step=1; } - my $num=1+int(($end-$start)/$step); - my $result=$start + int(&math_random_uniform() * $num)*$step; - return $result; + my ($start,$end,$step)=@_; + if ( ! $hidden::RANDOMINIT ) { + if ($external::randomseed == 0) { $external::randomseed=1; } + if ($external::randomseed =~/,/) { + my ($num1,$num2)=split(/,/,$seed); + &random_set_seed(abs($num1),abs($num2)); + } else { + &random_set_seed(1,int(abs($external::randomseed))); + } + &math_random_uniform(); + $hidden::RANDOMINIT=1; + } + if (!defined($step)) { $step=1; } + my $num=1+int(($end-$start)/$step); + my $result=$start + int(&math_random_uniform() * $num)*$step; + return $result; } sub random_normal {