Subject: | Non-unique numbers sometimes occur |
Date: | Fri, 19 Dec 2014 21:28:46 -0500 |
To: | bug-Data-Rand [...] rt.cpan.org |
From: | Malcolm Nooning <m.nooning [...] comcast.net> |
Hello,
As the test results at the bottom show, when extracting unique numbers,
I sometimes get repeats. The end goal is simply to get 20 random
numbers. I know there are other ways, but I really like the idea of
Data::Rand. If the bug is worked out Data::Rand would be very useful.
I am using Windows XP, perl 5, version 20, subversion 1 (v5.20.1) built
for MSWin32-x86-multi-thread-64int
I can do testing/leg work on my machine, if needed.
Thanks
---------------- Paste test code
# File: test_data_rand_fails.pl
use Data::Rand;
use strict;
my @nums_0_19 = 0..19;
my %results;
my @results;
print "Repeats of getting 20 random position numbers\n";
for (my $i=0; $i<10; $i++) {
%results = ();
@results = rand_data( 20, \@nums_0_19, { 'do_not_repeat_index' => 1
} );
print "All 20 numbers: @results\n";
foreach my $res (@results) {
if (!exists($results{$res})) {
$results{$res}++;
} else {
die("The result $res has been duplicated\n");
}
}
}
__END__
Show quoted text
>perl test_data_rand_fails.pl
Repeats of getting 20 random position numbers
All 20 numbers: 2 4 15 9 11 3 18 0 7 12 10 19 16 17 13 14 5 8 1 6
All 20 numbers: 18 15 17 13 5 7 14 3 16 11 1 4 19 0 8 12 2 6 9 10
All 20 numbers: 19 1 0 16 2 3 8 11 9 15 14 10 4 18 12 13 17 5 7 6
All 20 numbers: 13 3 8 11 16 9 5 19 15 6 18 17 14 12 4 1 0 2 17 7
The result 17 has been duplicated