Skip Menu |

This queue is for tickets about the Data-Rand CPAN distribution.

Report information
The Basics
Id: 101022
Status: open
Priority: 0/
Queue: Data-Rand

People
Owner: Nobody in particular
Requestors: m.nooning [...] comcast.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
Subject: Re: [rt.cpan.org #101022] AutoReply: Non-unique numbers sometimes occur
Date: Sat, 20 Dec 2014 08:01:37 -0500
To: bug-Data-Rand [...] rt.cpan.org
From: Malcolm Nooning <m.nooning [...] comcast.net>
I found the routine shuffle, in List::Util, that fulfills my need. Still, Data::Rand might fill someone else's needs, if fixed. On 12/19/2014 9:28 PM, Bugs in Data-Rand via RT wrote: Show quoted text
> Greetings, > > This message has been automatically generated in response to the > creation of a trouble ticket regarding: > "Non-unique numbers sometimes occur", > a summary of which appears below. > > There is no need to reply to this message right now. Your ticket has been > assigned an ID of [rt.cpan.org #101022]. Your ticket is accessible > on the web at: > > https://rt.cpan.org/Ticket/Display.html?id=101022 > > Please include the string: > > [rt.cpan.org #101022] > > in the subject line of all future correspondence about this issue. To do so, > you may reply to this message. > > Thank you, > bug-Data-Rand@rt.cpan.org > > ------------------------------------------------------------------------- > 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__ >
> >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 > >
Thanks! I’ll take a look asap