txt: ## roll.md
  roll
  
  Combined from primary sources listed below.
  
  # [In List](#___top "go to top of document")[§](#(List)_routine_roll "direct link")
  
  See primary documentation
  [in context](/type/List#routine_roll)
  for **routine roll**.
  
  ```raku
  multi        roll($count, *@list --> Seq:D)
  multi method roll(List:D: $count --> Seq:D)
  multi method roll(List:D: --> Mu)
  ```
  
  If `$count` is supplied: Returns a sequence of `$count` elements, each randomly selected from the list. Each random choice is made independently, like a separate die roll where each die face is a list element. If `*` is passed as `$count` returns a lazy, infinite sequence of randomly chosen elements from the original list.
  
  If `$count` is omitted: Returns a single random item from the list, or Nil if the list is empty
  
  Examples:
  
  ```raku
  say <a b c d e>.roll;       # 1 random letter
  say <a b c d e>.roll: 3;    # 3 random letters
  say roll 8, <a b c d e>;    # 8 random letters
  
  my $random-digits := (^10).roll(*);
  say $random-digits[^15];    # 15 random digits
  ```
  
  # [In role Baggy](#___top "go to top of document")[§](#(role_Baggy)_method_roll "direct link")
  
  See primary documentation
  [in context](/type/Baggy#method_roll)
  for **method roll**.
  
  ```raku
  multi method roll(Baggy:D: --> Any:D)
  multi method roll(Baggy:D: $count --> Seq:D)
  ```
  
  Like an ordinary list [roll](/type/List#routine_roll), 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 roll used. The underlying metaphor for rolling is that you're throwing `$count` dice that are independent of each other, which (in bag terms) is equivalent to picking a colored marble out your bag and then putting it back, and doing this `$count` times. In dice terms, the number of marbles corresponds to the number of sides, and the number of marbles of the same color corresponds to the number of sides with the same color. (For "picking without replacement" see [pick](#method_pick) instead).
  
  If `*` is passed to `$count`, returns a lazy, infinite sequence of randomly chosen elements from the invocant.
  
  ```raku
  my $breakfast = bag <eggs bacon bacon bacon>;
  say $breakfast.roll;                                  # OUTPUT: «bacon␤»
  say $breakfast.roll(3);                               # OUTPUT: «(bacon eggs bacon)␤»
  
  my $random_dishes := $breakfast.roll(*);
  say $random_dishes[^5];                               # OUTPUT: «(bacon eggs bacon bacon bacon)␤»
  ```
  
  # [In enum Bool](#___top "go to top of document")[§](#(enum_Bool)_routine_roll "direct link")
  
  See primary documentation
  [in context](/type/Bool#routine_roll)
  for **routine roll**.
  
  ```raku
  multi method roll(Bool:U --> Bool:D)
  multi method roll(Bool:U $count --> Seq:D)
  ```
  
  Returns `True` or `False` if called without any argument. Otherwise returns `$count` elements chosen at random. Note that each random choice from the `enum` is made independently, like a separate coin toss where each side of the coin represents one of the two values of the `enum`. If `*` is passed as `$count` an infinite [`Seq`](/type/Seq) of `Bool`s is returned.
  
  ```raku
  say Bool.roll;                                    # OUTPUT: «True␤»
  say Bool.roll(3);                                 # OUTPUT: «(True False False)␤»
  say Bool.roll(*);                                 # OUTPUT: «(...)␤»
  ```
  
  # [In role Enumeration](#___top "go to top of document")[§](#(role_Enumeration)_method_roll "direct link")
  
  See primary documentation
  [in context](/type/Enumeration#method_roll)
  for **method roll**.
  
  ```raku
  multi method roll(::?CLASS:U:)
  multi method roll(::?CLASS:U: \n)
  multi method roll(::?CLASS:D: *@pos)
  ```
  
  They work on the defined class selecting one or `n` elements without eliminating them.
  
  ```raku
  say Norse-gods.roll() for ^3;  # OUTPUT: «Freija␤Freija␤Oðin␤»
  
  ```
  
  # [In Range](#___top "go to top of document")[§](#(Range)_method_roll "direct link")
  
  See primary documentation
  [in context](/type/Range#method_roll)
  for **method roll**.
  
  ```raku
  multi method roll(Range:D:         --> Any:D)
  multi method roll(Range:D: $number --> Seq:D)
  ```
  
  Performs the same function as `Range.list.roll`, but attempts to optimize by not actually generating the list if it is not necessary.
  
  # [In Any](#___top "go to top of document")[§](#(Any)_method_roll "direct link")
  
  See primary documentation
  [in context](/type/Any#method_roll)
  for **method roll**.
  
  ```raku
  multi method roll(--> Any)
  multi method roll($n --> Seq)
  ```
  
  Coerces the invocant to a `list` by applying its [`.list`](/routine/list) method and uses [`List.roll`](/type/List#routine_roll) on it.
  
  ```raku
  my Mix $m = ("þ" xx 3, "ð" xx 4, "ß" xx 5).Mix;
  say $m.roll;    # OUTPUT: «ð␤»
  say $m.roll(5); # OUTPUT: «(ß ß þ ß þ)␤»
  ```
  
  `$m`, in this case, is converted into a list and then a (weighted in this case) dice is rolled on it. See also [`List.roll`](/type/List#routine_roll) for more information.
  
  # [In role Setty](#___top "go to top of document")[§](#(role_Setty)_method_roll "direct link")
  
  See primary documentation
  [in context](/type/Setty#method_roll)
  for **method roll**.
  
  ```raku
  multi method roll($count = 1)
  ```
  
  Returns a lazy list of `$count` elements, each randomly selected from the set. Each random choice is made independently, like a separate die roll where each die face is a set element.
  
  If `*` is passed as `$count`, the list is infinite.
  
  # [In role Mixy](#___top "go to top of document")[§](#(role_Mixy)_method_roll "direct link")
  
  See primary documentation
  [in context](/type/Mixy#method_roll)
  for **method roll**.
  
  ```raku
  method roll($count = 1)
  ```
  
  Similar to a [`Bag`](/type/Bag).roll, but with [`Real`](/type/Real) weights rather than integral ones.
  