in reply to Re^2: Curious find while comparing grep, map, and smart match...
in thread Curious find while comparing grep, map, and smart match...
I will make an effort to interpret BrowserUKs terse comment for you :-)
In grepGen/mapGen/smartGen you have a redo in the event of a collision, whereas if you really want unique random numbers, they could be generated much more simply by the shuffle method he suggested. His method does not involve repeated retries and removes the need for any of these functions. His one liner does what each of the three methods you proposed does, but much more efficiently....
my @rands = ( shuffle # shuffle, like a pack of cards 1 .. 120 # a series of numbers from 1..120 ) [ 0 .. 99 ]; # take the first 100 of these # the resulting @rands is a 100 element array of numbers # in the range 1..120, all of which are unique
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Curious find while comparing grep, map, and smart match...
by dbuckhal (Chaplain) on Mar 27, 2013 at 15:34 UTC | |
by BrowserUk (Patriarch) on Mar 27, 2013 at 15:48 UTC | |
by dbuckhal (Chaplain) on Mar 27, 2013 at 17:19 UTC | |
by space_monk (Chaplain) on Mar 27, 2013 at 17:46 UTC | |
by dbuckhal (Chaplain) on Mar 27, 2013 at 19:17 UTC | |
by BrowserUk (Patriarch) on Mar 27, 2013 at 17:45 UTC | |
by dbuckhal (Chaplain) on Mar 27, 2013 at 18:50 UTC | |
|