Pick random element: Difference between revisions

Content deleted Content added
Grondilu (talk | contribs)
→‎{{header|Perl 6}}: splitting the answer in a TL;DR version and a long version
Grondilu (talk | contribs)
→‎{{header|Perl 6}}: arguably better: phrasing instead of using subsections
Line 396:
 
=={{header|Perl 6}}==
 
===Short answer===
PickingIn a nutshell, picking an element from a list is implemented with a method conveniently called "pick":
<lang Perl 6>say (1, 2, 3).pick;</lang>
 
There are various ways of doing something similar, though. Perl 6 has actually two methods (with associated functional forms) to return random elements depending on whether you are doing selection with or without replacement.
===Long answer===
Perl 6 has 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)