in reply to Picking unique element in random from a array
rsriram,
Here is a way to do it.
use strict; use warnings; use Data::Random qw(:all); my @array = (1, 2, 1..120); #assign values to array my @ten = rand_set( set => \@array, size => 10 );#get random print "Ten unique random numbers: @ten";
updated: Added random module. Removed identifying unique elements as per L~R's advice. As far as runtime is concerned, it is not most efficient way though. Take a look at Limbic~Region node or davorg's. Limbic~Region Thanks.
Prasad
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Picking unique element in random from a array
by Limbic~Region (Chancellor) on Aug 09, 2006 at 12:47 UTC |