# Documentation for routine pick

Documentation for routine pick, assembled from the following types:

# class List

From List

## (List) routine pick

Defined as:

```
multi sub pick($count, *@list) returns Seq:D
multi method pick(List:D: $count = 1) returns Mu
```

Returns `$count`

elements chosen at random and without repetition from the invocant. If `*`

is passed as `$count`

, or `$count`

is greater than or equal to the size of the list, then all elements from the invocant list are returned in a random sequence.

Examples:

```
say <a b c d e>.pick; # b
say <a b c d e>.pick: 3; # (c a e)
say <a b c d e>.pick: *; # (e d a b c)
```

# role Baggy

From Baggy

## (Baggy) method pick

Defined as:

```
multi method pick(Baggy:D:) returns Any
multi method pick(Baggy:D: $count) returns Seq:D
```

Like an ordinary list pick, but returns keys of the invocant weighted by their values, as if the keys were replicated the number of times indicated by the corresponding value and then list pick used. The underlying metaphor for picking is that you're pulling colored marbles out a bag. (For "picking with replacement" see roll instead). If `*`

is passed as `$count`

, or `$count`

is greater than or equal to the total of the invocant, then `total`

elements from the invocant are returned in a random sequence.

Note that each `pick`

invocation maintains its own private state and has no effect on subsequent `pick`

invocations.

```
my $breakfast = bag <eggs bacon bacon bacon>;
say $breakfast.pick; # eggs
say $breakfast.pick(2); # (eggs bacon)
say $breakfast.total; # 4
say $breakfast.pick(*); # (bacon bacon bacon eggs)
```

# enum Bool

From Bool

## (Bool) routine pick

```
multi method pick(Bool:U) returns Bool:D
multi method pick(Bool:U $count) returns Seq:D
```

Returns `True`

or `False`

if called without any argument. Otherwise returns `$count`

elements chosen at random (without repetition) from the `enum`

. If `*`

is passed as `$count`

, or `$count`

is greater than or equal to two, then both elements are returned in random order.

```
say Bool.pick; # True
say Bool.pick(1); # (False)
say Bool.pick(*); # (False True)
```

# class Range

From Range

## (Range) method pick

```
multi method pick(Range:D: ) returns Any:D
multi method pick(Range:D: $number) returns Seq:D
```

Performs the same function as `Range.list.pick`

, but attempts to optimize by not actually generating the list if it is not necessary.

# role Setty

From Setty

## (Setty) method pick

```
multi method pick($count = 1)
```

Returns `$count`

elements chosen at random (without repetition) from the set.

If `*`

is passed as `$count`

, or `$count`

is greater than or equal to the size of the set, then all its elements are returned in random order.