#!/usr/bin/perl my $n = 1000; my $cnt = 10; my %ret; for (my $i = 0; $i < $cnt; $i++) { my $r = int(rand()*$n); $r++ while exists $ret{$r}; $ret{$r} = undef; $n--; } print "$cnt random indexes:\n"; foreach (keys %ret) { print "$_\n"; }
In reply to Re: Picking unique element in random from a array
by pajout
in thread Picking unique element in random from a array
by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |