Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to generate distinct random numbers?

by Aristotle (Chancellor)
on Sep 05, 2004 at 12:42 UTC ( [id://388596] : note . print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use List::Util qw( shuffle );
    
    ...
        return if $start > $end or $num > $end - $start + 1;
        ( shuffle $start .. $end )[ 0 .. $num - 1 ];
    }
    
  2. or download this
    use strict;
    use warnings;
    ...
            "retry($n,$s,$e)"   => sub { randseq_retry   $n, $s, $e },
        };
    }