We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e223c51 commit 168671eCopy full SHA for 168671e
docs/arrays/array_rand.txt
@@ -9,6 +9,21 @@ mixed array_rand ( array $input [, int $num_req = 1 ] )
9
**Perl
10
11
>|Perl|
12
-use List::Util qw(shuffle);
13
-@rand = shuffle @array;
+# FOR ARRAYS
+# when $num_req == 1:
14
+my $result = int rand @array;
15
+
16
+# otherwise:
17
+use Data::Random qw/ rand_set /;
18
+my @results = rand_set ( set => [0 .. $#array], size => $num_req );
19
20
+# FOR HASHES
21
22
+my @keys = keys %hash;
23
+my $result = $keys [ int rand @keys ];
24
25
26
27
28
+my @results = @keys [ rand_set ( set => [0 .. $#array], size => $num_req ) ];
29
||<
0 commit comments