in reply to How do I get my code to not repeat numbers and also sort the numbers
Since you need something closer to a grab bag, I would suggest you use a list of acceptable numbers. A great utility for mixing them is shuffle in List::Util. The following sample code populates an array with numbers between 1 and 30, mixes the bag, grabs 5 values, and then prints them:
use strict; use warnings; use List::Util qw(shuffle); my @bag = (1 .. 30); # Populate list using the range operator @bag = shuffle(@bag); # Shuffle the bag and store the results my @values = @bag[0..4]; # Get the first 5 results with an array slice print "Your numbers are @values\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Take out repeating numbers with grep
by tangieb01 (Novice) on Jun 10, 2010 at 00:05 UTC | |
by ikegami (Patriarch) on Jun 10, 2010 at 02:02 UTC | |
|
Re^2: How do I get my code to not repeat numbers and also sort the numbers
by tangieb01 (Novice) on Jun 09, 2010 at 23:07 UTC | |
by kennethk (Abbot) on Jun 09, 2010 at 23:11 UTC |