Deal: Difference between revisions

Jump to navigation Jump to search
434 bytes added ,  09:35, 4 June 2020
no edit summary
No edit summary
Line 1: Line 1:
{{Built-in|Deal|?}} is a [[dyadic]] [[primitive function]] which returns a random [[wikipedia:permutation#k-permutations of n|partial permutation]]. The name ''Deal'' comes from the analogy of [[wikipedia:card game#deal|dealing cards]] in a card game such as Poker. Both [[argument|arguments]] of <source lang=apl inline>k?n</source> must be non-negative integer [[scalar|scalars]] with <source lang=apl inline>k≤n</source>, and Deal generates a random k-permutation by selecting <source lang=apl inline>k</source> numbers from the first <source lang=apl inline>n</source> [[Index|indices]] without replacement. Some dialects, such as [[J]], treat Deal as a [[scalar function]]. Deal shares the [[glyph]] <source lang=apl inline>?</source> with the monadic scalar function [[Roll]].
{{Built-in|Deal|?}} is a [[dyadic]] [[primitive function]] which returns a random [[wikipedia:permutation#k-permutations of n|partial permutation]]. The name ''Deal'' comes from the analogy of [[wikipedia:card game#deal|dealing cards]] in a card game such as Poker. Both [[argument|arguments]] of <source lang=apl inline>k?n</source> must be non-negative integer [[scalar|scalars]] with <source lang=apl inline>k≤n</source>, and Deal generates a random k-permutation by selecting <source lang=apl inline>k</source> numbers from the first <source lang=apl inline>n</source> [[Index|indices]] without replacement. Deal shares the [[glyph]] <source lang=apl inline>?</source> with the monadic scalar function [[Roll]].


== Examples ==
== Examples ==
Line 24: Line 24:
└──┴──┴──┴──┴──┘
└──┴──┴──┴──┴──┘
</source>
</source>
[[J]] assigns [[function rank|rank]] 0 to Deal, so it can be used to generate multiple permutations at once. This behavior can be mimicked in other APLs by writing <source lang=apl inline>?⍤0</source>, which uses the [[Rank (operator)|rank operator]] <source lang=apl inline>⍤</source>.
<source lang=j>
      ?~ 5$10  NB. Generate five permutations of 0 to 9 at once
9 8 3 0 6 1 2 5 4 7
7 2 4 1 0 5 6 9 8 3
3 0 7 2 9 1 5 8 4 6
2 1 5 0 3 6 4 7 8 9
3 7 5 9 0 2 6 8 4 1
</source>{{Works in|[[J]]}}


== Description ==
== Description ==
trusted
183

edits

Navigation menu