Poll answers are now randomizable.
This commit is contained in:
parent
5c903b5c39
commit
80d9099815
3 changed files with 29 additions and 6 deletions
|
|
@ -15,7 +15,7 @@ use strict;
|
|||
use Tie::IxHash;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our @EXPORT = qw(&sortHashDescending &sortHash &isIn &randint &round);
|
||||
our @EXPORT = qw(&randomizeArray &sortHashDescending &sortHash &isIn &randint &round);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub isIn {
|
||||
|
|
@ -47,6 +47,17 @@ sub randint {
|
|||
return $low + int( rand( $high - $low + 1 ) );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub randomizeArray {
|
||||
my ($array, $i, $j);
|
||||
$array = shift;
|
||||
for ($i = @$array; --$i; ) {
|
||||
$j = int rand ($i+1);
|
||||
next if $i == $j;
|
||||
@$array[$i,$j] = @$array[$j,$i];
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub round {
|
||||
return sprintf("%.0f", $_[0]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue