[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm imageresponse.pm optionresponse.pm radiobuttonresponse.pm response.pm structuretags.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 26 Sep 2002 20:45:00 -0000
This is a MIME encoded message
--albertel1033073100
Content-Type: text/plain
albertel Thu Sep 26 16:45:00 2002 EDT
Modified files:
/loncom/homework default_homework.lcpm response.pm
radiobuttonresponse.pm optionresponse.pm
imageresponse.pm structuretags.pm
Log:
- removed use of Perl's internal rand operator, now all randomiztaion depends upon the external Math::Random library
--albertel1033073100
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20020926164500.txt"
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.50 loncom/homework/default_homework.lcpm:1.51
--- loncom/homework/default_homework.lcpm:1.50 Fri Sep 20 17:11:18 2002
+++ loncom/homework/default_homework.lcpm Thu Sep 26 16:45:00 2002
@@ -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.50 2002/09/20 21:11:18 albertel Exp $
+# $Id: default_homework.lcpm,v 1.51 2002/09/26 20:45:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -240,139 +240,171 @@
sub random {
my ($start,$end,$step)=@_;
if ( ! $hidden::RANDOMINIT ) {
- srand($external::randomseed);
+ &random_set_seed_from_phrase($external::randomseed);
$hidden::RANDOMINIT=1;
}
if (!defined($step)) { $step=1; }
my $num=1+int(($end-$start)/$step);
- my $result=$start + int(rand() * $num)*$step;
+ my $result=$start + int(&math_random_uniform() * $num)*$step;
return $result;
}
sub random_normal {
my ($item_cnt,$seed,$av,$std_dev) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_normal($item_cnt,$av,$std_dev);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_beta {
my ($item_cnt,$seed,$aa,$bb) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_beta($item_cnt,$aa,$bb);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_gamma {
my ($item_cnt,$seed,$a,$r) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_gamma($item_cnt,$a,$r);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_exponential {
my ($item_cnt,$seed,$av) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_exponential($item_cnt,$av);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_poisson {
my ($item_cnt,$seed,$mu) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_poisson($item_cnt,$mu);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_chi {
my ($item_cnt,$seed,$df) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_chi_square($item_cnt,$df);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_noncentral_chi {
my ($item_cnt,$seed,$df,$nonc) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_noncentral_chi_square($item_cnt,$df,$nonc);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_f {
my ($item_cnt,$seed,$dfn,$dfd) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_f($item_cnt,$dfn,$dfd);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_noncentral_f {
my ($item_cnt,$seed,$dfn,$dfd,$nonc) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_noncentral_f($item_cnt,$dfn,$dfd,$nonc);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_multivariate_normal {
my ($item_cnt,$seed,$mean,$covar) = @_;
+ my @oldseed=&random_get_seed();
&random_set_seed_from_phrase($seed);
@retArray=&math_random_multivariate_normal($item_cnt,@$mean,@$covar);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_multinomial {
my ($item_cnt,$seed,@p) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_multinomial($item_cnt,@p);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_permutation {
my ($seed,@inArray) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_permutation(@inArray);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_uniform {
my ($item_cnt,$seed,$low,$high) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_uniform($item_cnt,$low,$high);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_uniform_integer {
my ($item_cnt,$seed,$low,$high) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_uniform_integer($item_cnt,$low,$high);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_binomial {
my ($item_cnt,$seed,$nt,$p) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_binomial($item_cnt,$nt,$p);
+ &random_set_seed(@oldseed);
return @retArray;
}
sub random_negative_binomial {
my ($item_cnt,$seed,$ne,$p) = @_;
+ my @oldseed=&random_get_seed();
my @retArray;
&random_set_seed_from_phrase($seed);
@retArray=&math_random_negative_binomial($item_cnt,$ne,$p);
+ &random_set_seed(@oldseed);
return @retArray;
}
@@ -501,6 +533,7 @@
sub map {
my ($phrase,$dest,$source)=@_;
+ my @oldseed=&random_get_seed();
my @seed = &random_seed_from_phrase($phrase);
&random_set_seed(@seed);
my $destct = scalar(@$dest);
@@ -512,6 +545,7 @@
$output[$ctr] = $$dest[$idx[$ctr]];
$ctr++;
}
+ &random_set_seed(@oldseed);
return @output;
} else {
my $num = scalar(@$source);
@@ -531,10 +565,13 @@
}
}
}
+ &random_set_seed(@seed);
+ return '';
}
sub rmap {
my ($phrase,$dest,$source)=@_;
+ my @oldseed=&random_get_seed();
my @seed = &random_seed_from_phrase($phrase);
&random_set_seed(@seed);
my $destct = scalar(@$dest);
@@ -552,6 +589,7 @@
$output[$ctr] = $$dest[$r_idx[$ctr]];
$ctr++;
}
+ &random_set_seed(@oldseed);
return @output;
} else {
my $num = scalar(@$source);
@@ -577,6 +615,8 @@
}
}
}
+ &random_set_seed(@oldseed);
+ return '';
}
sub capa_id { return }
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.63 loncom/homework/response.pm:1.64
--- loncom/homework/response.pm:1.63 Mon Jul 29 16:40:34 2002
+++ loncom/homework/response.pm Thu Sep 26 16:45:00 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# various response type definitons response definition
#
-# $Id: response.pm,v 1.63 2002/07/29 20:40:34 albertel Exp $
+# $Id: response.pm,v 1.64 2002/09/26 20:45:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -91,7 +91,7 @@
$rndseed=$rndseed
+&Apache::lonnet::numval($Apache::inputtags::response['-1']);
}
- srand($rndseed);
+ &Math::Random::random_set_seed_from_phrase($rndseed);
&Apache::lonxml::debug("randseed $rndseed");
return '';
}
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.50 loncom/homework/radiobuttonresponse.pm:1.51
--- loncom/homework/radiobuttonresponse.pm:1.50 Wed Sep 25 15:39:49 2002
+++ loncom/homework/radiobuttonresponse.pm Thu Sep 26 16:45:00 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# mutliple choice style responses
#
-# $Id: radiobuttonresponse.pm,v 1.50 2002/09/25 19:39:49 albertel Exp $
+# $Id: radiobuttonresponse.pm,v 1.51 2002/09/26 20:45:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -218,7 +218,7 @@
my $count=0;
# we will add in 1 of the true statements
if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
- my $answer=int(rand($count));
+ my $answer=int(&Math::Random::random_uniform() * ($count));
&Apache::lonxml::debug("Count is $count, $answer is $answer");
my @names;
if ( $Apache::response::foilgroup{'names'} ) {
@@ -268,7 +268,7 @@
}
}
#pick a true statement
- my $whichtrue = int(rand($#truelist+1));
+ my $whichtrue = int(&Math::Random::random_uniform() * ($#truelist+1));
&Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
my $numinserted;
my (@toplist, @bottomlist);
@@ -277,7 +277,7 @@
# which false is randomized, toplist bottomlist are in order
while ((($numinserted) < $max-1) && ($#falselist > -1)) {
&Apache::lonxml::debug("Have $#whichfalse max is $max");
- my $afalse=int(rand($#falselist+1));
+ my $afalse=int(&Math::Random::random_uniform() * ($#falselist+1));
&Apache::lonxml::debug("From $#falselist elms, picking $afalse");
$afalse=splice(@falselist,$afalse,1);
&Apache::lonxml::debug("Picked $afalse");
@@ -313,7 +313,10 @@
$answer+=$topcount+$#whichfalse+1;
$dosplice=0;
} else {
- if ($topcount>0) { $answer = int(rand($#whichfalse+1))+$topcount; }
+ if ($topcount>0) {
+ $answer = int(&Math::Random::random_uniform() * ($#whichfalse+1))
+ + $topcount;
+ }
}
#add the top items to the top, bottom items to the bottom
for (my $i=0;$i<=$#toplist;$i++) {
@@ -412,7 +415,7 @@
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
if (defined(@{ $Apache::response::conceptgroup{'names'} })) {
my @names = @{ $Apache::response::conceptgroup{'names'} };
- my $pick=int(rand($#names+1));
+ my $pick=int(&Math::Random::random_uniform() * ($#names+1));
my $name=$names[$pick];
push @{ $Apache::response::foilgroup{'names'} }, $name;
$Apache::response::foilgroup{"$name.text"} = $Apache::response::conceptgroup{"$name.text"};
@@ -443,8 +446,12 @@
$result.=&Apache::edit::text_arg('Name:','name',$token);
$result.=&Apache::edit::select_or_text_arg('Correct Option:','value',
['unused','true','false'],$token);
- $result.=&Apache::edit::select_arg('Location:','location',
- ['random','bottom','top'],$token);
+ my $randomize=&Apache::lonxml::get_param('randomize',$parstack,
+ $safeeval,'-3');
+ if ($randomize eq 'yes') {
+ $result.=&Apache::edit::select_arg('Location:','location',
+ ['random','bottom','top'],$token);
+ }
$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.46 loncom/homework/optionresponse.pm:1.47
--- loncom/homework/optionresponse.pm:1.46 Mon Aug 26 14:15:22 2002
+++ loncom/homework/optionresponse.pm Thu Sep 26 16:45:00 2002
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.46 2002/08/26 18:15:22 sakharuk Exp $
+# $Id: optionresponse.pm,v 1.47 2002/09/26 20:45:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -243,7 +243,7 @@
if (&Apache::response::showallfoils()) {
$aopt=0;
} else {
- $aopt=int(rand($#names+1));
+ $aopt=int(&Math::Random::random_uniform() * ($#names+1));
}
&Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt");
$aopt=splice(@names,$aopt,1);
@@ -373,7 +373,7 @@
#if not there aren't any foils to display and thus no question
if (defined(@{ $Apache::response::conceptgroup{'names'} })) {
my @names = @{ $Apache::response::conceptgroup{'names'} };
- my $pick=int rand $#names+1;
+ my $pick=int(&Math::Random::random_uniform() * ($#names+1));
my $name=$names[$pick];
push @{ $Apache::response::foilgroup{'names'} }, $name;
$Apache::response::foilgroup{"$name.value"} =
Index: loncom/homework/imageresponse.pm
diff -u loncom/homework/imageresponse.pm:1.21 loncom/homework/imageresponse.pm:1.22
--- loncom/homework/imageresponse.pm:1.21 Sat Aug 24 11:26:43 2002
+++ loncom/homework/imageresponse.pm Thu Sep 26 16:45:00 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# image click response style
#
-# $Id: imageresponse.pm,v 1.21 2002/08/24 15:26:43 harris41 Exp $
+# $Id: imageresponse.pm,v 1.22 2002/09/26 20:45:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -85,7 +85,7 @@
if (&Apache::response::showallfoils()) {
$aopt=0;
} else {
- $aopt=int(rand($#names+1));
+ $aopt=int(&Math::Random::random_uniform() * ($#names+1));
}
&Apache::lonxml::debug("From $#names elms, picking $aopt");
$aopt=splice(@names,$aopt,1);
@@ -184,7 +184,7 @@
if ($target eq 'web' || $target eq 'grade') {
if (defined(@{ $Apache::response::conceptgroup{'names'} })) {
my @names = @{ $Apache::response::conceptgroup{'names'} };
- my $pick=int(rand($#names+1));
+ my $pick=int(&Math::Random::random_uniform() * ($#names+1));
my $name=$names[$pick];
if (defined(@{ $Apache::response::conceptgroup{"$name.area"} })) {
push @{ $Apache::response::foilgroup{'names'} }, $name;
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.117 loncom/homework/structuretags.pm:1.118
--- loncom/homework/structuretags.pm:1.117 Mon Sep 23 17:08:03 2002
+++ loncom/homework/structuretags.pm Thu Sep 26 16:45:00 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.117 2002/09/23 21:08:03 sakharuk Exp $
+# $Id: structuretags.pm,v 1.118 2002/09/26 20:45:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -603,7 +603,7 @@
if (defined(@$a)) {
&Apache::response::setrandomnumber();
for($i=@$a;--$i;) {
- my $j=int rand($i+1);
+ my $j=int(&Math::Random::random_uniform() * ($i+1));
next if $i == $j;
@$a[$i,$j] = @$a[$j,$i];
}
--albertel1033073100--