Pick random element: Difference between revisions

Content deleted Content added
SqrtNegInf (talk | contribs)
m →‎{{header|Perl 6}}: fixed definition of deck
Line 618:
 
=={{header|Perl 6}}==
{{Works with|rakudo|2015-12-07}}
 
In a nutshell, picking an element from a list
is implemented with a method conveniently called "pick":
Line 635:
Selection without replacement: (pick a card from a deck)
<lang perl6># define the deck
constantmy @deck = <2.. 3 4 5 6 7 8 9, <J Q K A> X~ <♠ ♣ ♥ ♦>;
@deck.pick; # Pick a card
@deck.pick(5); # Draw 5
@deck.pick(*); # Get a shuffled deck</lang>
Or you can always use the normal <tt>rand</tt> built-in
to generate a subscript (which automatically truncates any fractional part):