From 2e894e05cc886dbb15e2c4312343ac84fa4ceef1 Mon Sep 17 00:00:00 2001 From: "David A. Madore" Date: Thu, 4 Jun 2020 15:50:53 +0200 Subject: Test randomizer script: change uniformity rules. --- misc/randomize-test.pl | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/misc/randomize-test.pl b/misc/randomize-test.pl index 2db3998..e569adb 100755 --- a/misc/randomize-test.pl +++ b/misc/randomize-test.pl @@ -11,10 +11,15 @@ my %opts; getopts("c:N:n:", \%opts); -my @preamble = (); -my @postamble = (); -my @questions = (); -my $nbvarid = 0; +my @preamble = (); # Preamble lines +my @postamble = (); # Postamble lines +my @questions = (); # Array of question hashrefs +# Each question hash has keys: +# {question}: arrayref with question lines +# {answers}: arrayref of arrayrefs with answer lines, correct answer first +# {varid}: idnex in qvars array +my @qvars = (); # Array of question variants +# Each entry is an arrayref of indexes in the questions array ### READ INPUT FILE @@ -45,23 +50,23 @@ while ($_ = <>) { die "wrong placement" if $in_preamble || $in_postamble || $in_qvar || defined($curqn); die "bad format" unless $_ eq "\\begin\{qvar\}\n"; $in_qvar = 1; - $varid = ($nbvarid++); + push @qvars, []; next LINELOOP; } elsif ( $_ =~ m/\\end\{qvar\}/ ) { die "wrong placement" if $in_preamble || $in_postamble || (!$in_qvar) || defined($curqn); die "bad format" unless $_ eq "\\end\{qvar\}\n"; $in_qvar = 0; - $varid = undef; next LINELOOP; } elsif ( $_ =~ m/\\begin\{question\}/ ) { die "wrong placement" if $in_preamble || $in_postamble || defined($curqn); die "bad format" unless $_ eq "\\begin\{question\}\n"; my %qn = (); - $varid = ($nbvarid++) unless $in_qvar; - $qn{varid} = $varid; + push @qvars, [] unless $in_qvar; + $qn{varid} = $#qvars; $qn{question} = []; $qn{answers} = []; push @questions, \%qn; + push @{$qvars[$#qvars]}, $#questions; $listref = $qn{question}; $curqn = \%qn; next LINELOOP; @@ -90,14 +95,12 @@ while ($_ = <>) { } -# printf STDERR "nbvarid=%d (total=%d)\n", $nbvarid, scalar(@questions); - ### RANDOMIZE my $commonseed = $opts{N} // ""; my $seed = $opts{n} // ""; -my $nbqn = $opts{c} // int(($nbvarid+1)/2); +my $nbqn = $opts{c} // int((scalar(@qvars)+1)/2); my @questab = (); my @quesanstab = (); @@ -106,24 +109,21 @@ if ( 1 ) { ## Keep following variables local my @hashlist; -for ( my $i=0 ; $i $nbqn; - my $i = $prequestab[$k]; - my $qn = $questions[$i]; - my $varid = $qn->{varid}; - if ( defined($varid) ) { - if ( defined($varid_punch{$varid}) ) { - next PREQUESLOOP; - } else { - $varid_punch{$varid} = $i; - } +my @qvartab = sort { $hashlist[$a] cmp $hashlist[$b] } (0..(scalar(@qvars)-1)); + +for ( my $k=0 ; $k[$kv]; + push @hashlist, sha256("${commonseed}\n${seed}\nQ\n${i}\n"); } + my $kv = (sort { $hashlist[$a] cmp $hashlist[$b] } (0..(scalar(@{$qvars[$u]})-1)))[0]; + my $i = $qvars[$u]->[$kv]; + die "this is impossible" unless $questions[$i]->{varid} == $u; push @questab, $i; } @@ -158,13 +158,13 @@ for ( my $k=0 ; $k{question}} ) { print $l; } - for ( my $kk=0 ; $kk[$kk]; + for ( my $kj=0 ; $kj[$kj]; my $a = $qn->{answers}->[$j]; foreach my $l ( @{$a} ) { print $l; } - push @correct, sprintf("%d%s", $k+1, chr(ord("A")+$kk)) if $j==0; + push @correct, sprintf("%d%s", $k+1, chr(ord("A")+$kj)) if $j==0; } print "\\end\{question\}\n\n"; } -- cgit v1.2.3