version 1.125, 2005/09/23 16:47:06
|
version 1.127, 2005/11/03 23:00:53
|
Line 94 sub pushrandomnumber {
|
Line 94 sub pushrandomnumber {
|
# do nothing |
# do nothing |
} else { |
} else { |
my @seed=&Math::Random::random_get_seed(); |
my @seed=&Math::Random::random_get_seed(); |
push (@randomseeds,\@seed); |
push(@randomseeds,\@seed); |
} |
} |
&Apache::response::setrandomnumber(); |
&Apache::response::setrandomnumber(@_); |
} |
} |
sub poprandomnumber { |
sub poprandomnumber { |
my $rand_alg=&Apache::lonnet::get_rand_alg(); |
my $rand_alg=&Apache::lonnet::get_rand_alg(); |
Line 113 sub poprandomnumber {
|
Line 113 sub poprandomnumber {
|
} |
} |
|
|
sub setrandomnumber { |
sub setrandomnumber { |
|
my ($ignore_id2) = @_; |
my $rndseed; |
my $rndseed; |
$rndseed=&Apache::structuretags::setup_rndseed(); |
$rndseed=&Apache::structuretags::setup_rndseed(); |
if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); } |
if (!defined($rndseed)) { $rndseed=&Apache::lonnet::rndseed(); } |
&Apache::lonxml::debug("randseed $rndseed"); |
&Apache::lonxml::debug("randseed $rndseed"); |
# $rndseed=unpack("%32i",$rndseed); |
# $rndseed=unpack("%32i",$rndseed); |
my $rand_alg=&Apache::lonnet::get_rand_alg(); |
my $rand_alg=&Apache::lonnet::get_rand_alg(); |
my $rndmod; |
my ($rndmod,$rndmod2); |
|
|
my ($id1,$id2,$shift_amt); |
my ($id1,$id2,$shift_amt); |
if ($Apache::lonhomework::parsing_a_problem) { |
if ($Apache::lonhomework::parsing_a_problem) { |
Line 130 sub setrandomnumber {
|
Line 131 sub setrandomnumber {
|
$shift_amt=scalar(@Apache::inputtags::responselist); |
$shift_amt=scalar(@Apache::inputtags::responselist); |
} elsif ($Apache::lonhomework::parsing_a_task) { |
} elsif ($Apache::lonhomework::parsing_a_task) { |
$id1=$Apache::bridgetask::dimension; |
$id1=$Apache::bridgetask::dimension; |
if (defined($Apache::bridgetask::instance[-1])) { |
if (!$ignore_id2 && defined($Apache::bridgetask::instance[-1])) { |
$id2=$Apache::bridgetask::instance[-1]; |
$id2=$Apache::bridgetask::instance[-1]; |
} |
} |
$shift_amt=scalar(@Apache::bridgetask::instance); |
$shift_amt=scalar(@Apache::bridgetask::instance); |
Line 143 sub setrandomnumber {
|
Line 144 sub setrandomnumber {
|
} elsif ($rand_alg eq '64bit3') { |
} elsif ($rand_alg eq '64bit3') { |
$rndmod=(&Apache::lonnet::numval2($id1) << 10); |
$rndmod=(&Apache::lonnet::numval2($id1) << 10); |
if (defined($id2)) { $rndmod+=&Apache::lonnet::numval2($id2); } |
if (defined($id2)) { $rndmod+=&Apache::lonnet::numval2($id2); } |
} else { |
} elsif ($rand_alg eq '64bit4') { |
my $shift=(4*$shift_amt)%30; |
my $shift=(4*$shift_amt)%30; |
$rndmod=(&Apache::lonnet::numval3($id1) << (($shift+15)%30)); |
$rndmod=(&Apache::lonnet::numval3($id1) << (($shift+15)%30)); |
if (defined($id2)) { |
if (defined($id2)) { |
$rndmod+=(&Apache::lonnet::numval3($id2) << $shift ); |
$rndmod+=(&Apache::lonnet::numval3($id2) << $shift ); |
} |
} |
|
} else { |
|
($rndmod,$rndmod2)=&Apache::lonnet::digest("$id1,$id2"); |
} |
} |
|
|
if ($rndseed =~/([,:])/) { |
if ($rndseed =~/([,:])/) { |
my $char=$1; |
my $char=$1; |
use integer; |
use integer; |
my ($num1,$num2)=split(/\Q$char\E/,$rndseed); |
my ($num1,$num2)=split(/\Q$char\E/,$rndseed); |
$num1+=$rndmod; |
$num1+=$rndmod; |
$num2+=$rndmod; |
$num2+= ((defined($rndmod2)) ? $rndmod2 : $rndmod); |
if($Apache::lonnet::_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
if($Apache::lonnet::_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
$rndseed=$num1.$char.$num2; |
$rndseed=$num1.$char.$num2; |
} else { |
} else { |