version 1.128, 2004/01/10 22:52:20
|
version 1.129, 2004/02/08 00:35:29
|
Line 974 sub PrintRandom {
|
Line 974 sub PrintRandom {
|
my %q; |
my %q; |
my $answer=$razd?0:1; |
my $answer=$razd?0:1; |
my @answers; |
my @answers; |
|
#my $t=time; |
my (@Questions) = &Get12Random($dbh, $type, $num); |
my (@Questions) = &Get12Random($dbh, $type, $num); |
my ($output, $i) = ('', 0); |
|
|
|
|
my ($output, $i) = ('', 0); |
|
#$output.="time=".(time-$t).p; |
if ($text) { |
if ($text) { |
$output .= " $num случайных вопросов.\n\n"; |
$output .= " $num случайных вопросов.\n\n"; |
} else { |
} else { |
Line 1479 sub Get12Random {
|
Line 1481 sub Get12Random {
|
srand; |
srand; |
my $where=0; |
my $where=0; |
my $r=int (rand(10000)); |
my $r=int (rand(10000)); |
|
my $w1=$r<5000? "QuestionId<5000 ":"QuestionId>=5000"; |
|
$w1=1 if $type!~/Ч/; |
foreach (split '', $type) |
foreach (split '', $type) |
{ |
{ |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
$where.= " OR (Type ='$_') OR (Type ='$_Д') "; |
Line 1489 sub Get12Random {
|
Line 1492 sub Get12Random {
|
# $q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
# $q="select QuestionId, QuestionId/$r-floor(QuestionId/$r) as val |
# from Questions where $where order by val limit $num"; |
# from Questions where $where order by val limit $num"; |
# Когда на куличках появится mysql >=3.23 надо заменить на order by rand(); |
# Когда на куличках появится mysql >=3.23 надо заменить на order by rand(); |
$q="select QuestionId from Questions where $where order by rand() limit $num"; |
$q="select QuestionId from Questions where ($w1) AND ($where) order by rand() limit $num"; |
|
|
|
|
$sth=$dbh->prepare($q); |
$sth=$dbh->prepare($q); |