deelinux has asked for the wisdom of the Perl Monks concerning the following question:
Hello (I'm new to perl and programming) Im trying to create 10 unique numbers from numbers 1 - 20, but every now and then I get duplicates in the listI would like to remove the duplicates or not get one in the first place. This is no doubt due to my coding, so I'm looking for some help. I have run both rand and srand - same results My code
Can anyone help here?$x=1; $y=20; $looptimes=10; while ($looptimes) { $mynumbers = int(rand ($y - $x + 1)) + $x, "\n"; print $mynumbers; $looptimes--; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl - Unique Numbers
by toolic (Bishop) on Oct 17, 2015 at 19:05 UTC | |
by bagyi (Acolyte) on Oct 18, 2015 at 04:22 UTC | |
Re: Perl - Unique Numbers
by AppleFritter (Vicar) on Oct 17, 2015 at 19:09 UTC | |
Re: Perl - Unique Numbers
by LanX (Saint) on Oct 18, 2015 at 02:43 UTC | |
Re: Perl - Unique Numbers
by flexvault (Monsignor) on Oct 17, 2015 at 19:27 UTC | |
by johngg (Canon) on Oct 17, 2015 at 23:08 UTC | |
by flexvault (Monsignor) on Oct 18, 2015 at 02:12 UTC | |
by dsheroh (Monsignor) on Oct 18, 2015 at 09:01 UTC | |
by flexvault (Monsignor) on Oct 18, 2015 at 15:28 UTC | |
| |
Re: Perl - Unique Numbers (algorithm)
by tye (Sage) on Oct 19, 2015 at 14:37 UTC | |
Re: Perl - Unique Numbers
by flexvault (Monsignor) on Oct 19, 2015 at 13:58 UTC | |
Re: Perl - Unique Numbers
by deelinux (Novice) on Oct 18, 2015 at 15:52 UTC |