Help for this page

Select Code to Download


  1. or download this
    use List::Util "shuffle";
    sub shuffleArray{   
            shuffle(@_);
    }
    
  2. or download this
    sub shuffleArray{
            my @p = @_;
    ...
                    0 .. @p - 1;
            @p;
    }
    
  3. or download this
    sub shuffleArray{
            my @p = @_;
            map { splice @p, $_ + rand(@p - $_), 1, $p[$_] } 0 .. @p - 1;
    }
    
  4. or download this
    sub shuffleArray{
            my @p = @_;
            my $t;
            map { $t = splice @p, rand(@p), 1, $p[0]; shift @p; $t } 0 .. 
    +@p - 1;
    }
    
  5. or download this
    sub shuffleArray{
            my @w = map { rand } @_; 
            @_[sort { $w[$a] <=> $w[$b] } 0 .. @_ - 1];
    }
    
  6. or download this
    sub shuffleArray{
            map { $$_[1] } sort { $$a[0] <=> $$b[0] } map { [rand, $_] } @
    +_;
    }
    
  7. or download this
    sub shuffleArray{
            map { $$_[0] } sort { ref $a <=> ref $b } map { bless [$_], ra
    +nd } @_;      
    }