Difference between revisions of "Roll"

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
Miraheze>Adám Brudzewsky
Line 11: Line 11:
 
eeHHHolo
 
eeHHHolo
 
</source>
 
</source>
{{Works in|[[Dyalog APL]], [[dzaima/APL]]}}
+
{{Works in|[[Dyalog APL]], [[NARS2000]], [[dzaima/APL]]}}
  
 
== Description ==
 
== Description ==

Revision as of 22:34, 29 October 2019

Template:Primitive is a monadic scalar function which returns random or pseudo-random numbers. Each scalar in the argument must be a positive integer, n, and Roll chooses one of the first n indices. Some dialects allow n to be zero, in which case Roll chooses a floating-point number between 0 and 1.

Examples

      ? 4  6                   ⍝ Roll four six-sided dice
1 4 1 1
      ? 3 2 1 0                 ⍝ The result for 1 is always 1
2 2 1 0.9637543707
      {[?8⍴≢]} 'Hello'        ⍝ Choose 8 random letters
eeHHHolo

Description

Each scalar in the argument to Roll must be a positive integer.

The result of Roll on each number n is either

  • One of the elements of n chosen uniformly at random; or
  • A real number between 0 and 1 chosen uniformly at random, if n is 0 and the dialect has this extension.

Because Iota depends on index origin, Roll depends on index origin unless every number in the argument is 0.

The choices made by Roll do not have to be truly random: they may be pseudorandom (generated by a deterministic but difficult to predict algorithm) or taken from the operating system. They way random numbers are generated is controlled by the random link ⎕RL.

External links

Lessons

Documentation

APL built-ins [edit]
Primitive functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Name classCase convertUnicode convert
Operators SearchReplace