Pick random element
In a nutshell, picking an element from a list is implemented with a method conveniently called "pick":
There are various ways of doing something similar, though. Raku has actually two methods (with associated functional forms) to return random elements depending on whether you are doing selection with or without replacement.
Selection with replacement: (roll of a die)
Selection without replacement: (pick a card from a deck)
Or you can always use the normal rand
built-in to generate a subscript (which automatically truncates any fractional part):
However, the pick
and roll
methods (not to be confused with the pick-and-roll method in basketball) are more general insofar as they may be used on any enumerable type:
Last updated