line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Algorithm::Numerical::Shuffle; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
647
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
31
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
27
|
|
7
|
1
|
|
|
1
|
|
3
|
no warnings 'syntax'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
8
|
1
|
|
|
1
|
|
4
|
use Exporter (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
199
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw /Exporter/; |
11
|
|
|
|
|
|
|
our @EXPORT = qw //; |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw /shuffle/; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '2009110301'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub shuffle { |
17
|
4
|
100
|
100
|
4
|
0
|
152
|
return @_ if !@_ || ref $_ [0] eq 'ARRAY' && !@{$_ [0]}; |
|
2
|
|
66
|
|
|
11
|
|
18
|
2
|
100
|
66
|
|
|
14
|
my $array = @_ == 1 && ref $_ [0] eq 'ARRAY' ? shift : [@_]; |
19
|
2
|
|
|
|
|
7
|
for (my $i = @$array; -- $i;) { |
20
|
18
|
|
|
|
|
63
|
my $r = int rand ($i + 1); |
21
|
18
|
|
|
|
|
48
|
($array -> [$i], $array -> [$r]) = ($array -> [$r], $array -> [$i]); |
22
|
|
|
|
|
|
|
} |
23
|
2
|
100
|
|
|
|
10
|
wantarray ? @$array : $array; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__END__ |