in reply to Picking unique element in random from a array
A slight change to your code can help:
my %seen; for my $x (0..9) { my $element = $quest[rand @quest]; redo if $seen{$element}++; print $element; }
You set the element as a key to the hash, and you test to see if you have already used that element.
--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Picking unique element in random from a array
by Limbic~Region (Chancellor) on Aug 09, 2006 at 13:29 UTC |