uG has asked for the wisdom of the Perl Monks concerning the following question:
I get a pretty vague error (Unknown error) from the above code, but its from the pop's. I suppose thats because shuffle is returning a list (and therefore cannot be pop'd?). Whats an elegant way to get 2 unique random numbers between 1 and x? It seems like it involves an ugly amount of code to do such a trival task :(use List::Util 'shuffle'; my @numbers = (1..10); my $r1 = pop(shuffle(@numbers)); my $r2 = pop(shuffle(@numbers));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Generating 2 unique random integers (So I can't pop a list...)
by BrowserUk (Patriarch) on Sep 11, 2008 at 04:55 UTC | |
|
Re: Generating 2 unique random integers (So I can't pop a list...)
by ikegami (Patriarch) on Sep 11, 2008 at 05:00 UTC | |
|
Re: Generating 2 unique random integers (So I can't pop a list...)
by salva (Canon) on Sep 11, 2008 at 06:56 UTC | |
by RMGir (Prior) on Sep 11, 2008 at 12:38 UTC | |
| |
|
Re: Generating 2 unique random integers (So I can't pop a list...)
by tilly (Archbishop) on Sep 11, 2008 at 15:34 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |