[LON-CAPA-cvs] cvs: loncom /homework response.pm /lonnet/perl lonnet.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 01 Nov 2005 21:34:09 -0000
albertel Tue Nov 1 16:34:09 2005 EDT
Modified files:
/loncom/homework response.pm
/loncom/lonnet/perl lonnet.pm
Log:
- 64bit5 more randomish looking, no longer trying to munge on our own, using Digest::MD5
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.125 loncom/homework/response.pm:1.126
--- loncom/homework/response.pm:1.125 Fri Sep 23 12:47:06 2005
+++ loncom/homework/response.pm Tue Nov 1 16:33:49 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# various response type definitons response definition
#
-# $Id: response.pm,v 1.125 2005/09/23 16:47:06 albertel Exp $
+# $Id: response.pm,v 1.126 2005/11/01 21:33:49 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -119,7 +119,7 @@
&Apache::lonxml::debug("randseed $rndseed");
# $rndseed=unpack("%32i",$rndseed);
my $rand_alg=&Apache::lonnet::get_rand_alg();
- my $rndmod;
+ my ($rndmod,$rndmod2);
my ($id1,$id2,$shift_amt);
if ($Apache::lonhomework::parsing_a_problem) {
@@ -133,6 +133,7 @@
if (defined($Apache::bridgetask::instance[-1])) {
$id2=$Apache::bridgetask::instance[-1];
}
+ Apache->request->print("<p> $id1 $id2</p>");
$shift_amt=scalar(@Apache::bridgetask::instance);
}
&Apache::lonxml::debug("id1: $id1, id2: $id2, shift_amt: $shift_amt");
@@ -143,19 +144,22 @@
} elsif ($rand_alg eq '64bit3') {
$rndmod=(&Apache::lonnet::numval2($id1) << 10);
if (defined($id2)) { $rndmod+=&Apache::lonnet::numval2($id2); }
- } else {
+ } elsif ($rand_alg eq '64bit4') {
my $shift=(4*$shift_amt)%30;
$rndmod=(&Apache::lonnet::numval3($id1) << (($shift+15)%30));
if (defined($id2)) {
$rndmod+=(&Apache::lonnet::numval3($id2) << $shift );
}
+ } else {
+ ($rndmod,$rndmod2)=&Apache::lonnet::digest("$id1,$id2");
+
}
if ($rndseed =~/([,:])/) {
my $char=$1;
use integer;
my ($num1,$num2)=split(/\Q$char\E/,$rndseed);
$num1+=$rndmod;
- $num2+=$rndmod;
+ $num2+= ((defined($rndmod2)) ? $rndmod2 : $rndmod);
if($Apache::lonnet::_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); }
$rndseed=$num1.$char.$num2;
} else {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.674 loncom/lonnet/perl/lonnet.pm:1.675
--- loncom/lonnet/perl/lonnet.pm:1.674 Tue Nov 1 10:07:29 2005
+++ loncom/lonnet/perl/lonnet.pm Tue Nov 1 16:34:04 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.674 2005/11/01 15:07:29 www Exp $
+# $Id: lonnet.pm,v 1.675 2005/11/01 21:34:04 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -5379,8 +5379,37 @@
return $total;
}
+sub digest {
+ my ($data)=@_;
+ my $digest=&Digest::MD5::md5($data);
+ my ($a,$b,$c,$d)=unpack("iiii",$digest);
+ my ($e,$f);
+ {
+ use integer;
+ $e=($a+$b);
+ $f=($c+$d);
+ if ($_64bit) {
+ $e=(($e<<32)>>32);
+ $f=(($f<<32)>>32);
+ }
+ }
+ if (wantarray) {
+ return ($e,$f);
+ } else {
+ my $g;
+ {
+ use integer;
+ $g=($e+$f);
+ if ($_64bit) {
+ $g=(($g<<32)>>32);
+ }
+ }
+ return $g;
+ }
+}
+
sub latest_rnd_algorithm_id {
- return '64bit4';
+ return '64bit5';
}
sub get_rand_alg {
@@ -5420,11 +5449,15 @@
if (!$username) { $username=$wusername }
my $which=&get_rand_alg();
if (defined(&getCODE())) {
- if ($which eq '64bit4') {
+ if ($which eq '64bit5') {
+ return &rndseed_CODE_64bit5($symb,$courseid,$domain,$username);
+ } elsif ($which eq '64bit4') {
return &rndseed_CODE_64bit4($symb,$courseid,$domain,$username);
} else {
return &rndseed_CODE_64bit($symb,$courseid,$domain,$username);
}
+ } elsif ($which eq '64bit5') {
+ return &rndseed_64bit5($symb,$courseid,$domain,$username);
} elsif ($which eq '64bit4') {
return &rndseed_64bit4($symb,$courseid,$domain,$username);
} elsif ($which eq '64bit3') {
@@ -5547,6 +5580,12 @@
}
}
+sub rndseed_64bit5 {
+ my ($symb,$courseid,$domain,$username)=@_;
+ my ($num1,$num2)=&digest("$symb,$courseid,$domain,$username");
+ return "$num1:$num2";
+}
+
sub rndseed_CODE_64bit {
my ($symb,$courseid,$domain,$username)=@_;
{
@@ -5585,6 +5624,13 @@
}
}
+sub rndseed_CODE_64bit5 {
+ my ($symb,$courseid,$domain,$username)=@_;
+ my $code = &getCODE();
+ my ($num1,$num2)=&digest("$symb,$courseid,$code");
+ return "$num1:$num2";
+}
+
sub setup_random_from_rndseed {
my ($rndseed)=@_;
if ($rndseed =~/([,:])/) {