Roll: Difference between revisions

Jump to navigation Jump to search
186 bytes added ,  19:52, 29 October 2019
no edit summary
Miraheze>Adám Brudzewsky
Miraheze>Adám Brudzewsky
No edit summary
Line 1: Line 1:
{{Primitive|?|Roll}} is a [[monadic]] [[scalar function]] which returns random or pseudo-random numbers. Each [[scalar]] in the argument must be a non-negative integer. If it is a positive number <source lang=apl inline>n</source>, then Roll chooses one of the first <source lang=apl inline>n</source> [[Index|indices]]. In some dialects Roll chooses a floating-point number between 0 and 1 when the argument has a zero.
{{Primitive|?|Roll}} is a [[monadic]] [[scalar function]] which returns random or pseudo-random numbers. Each [[scalar]] in the argument must be a positive integer, <source lang=apl inline>n</source>, and Roll chooses one of the first <source lang=apl inline>n</source> [[Index|indices]]. Some dialects allow <source lang=apl inline>n</source> to be zero, in which case Roll chooses a floating-point number between 0 and 1.


== Examples ==
== Examples ==
Line 15: Line 15:
== Description ==
== Description ==


Each [[scalar]] in the argument to Roll must be a non-negative integer.
Each [[scalar]] in the argument to Roll must be a positive integer.


The result of Roll on each number <source lang=apl inline>n</source> is either
The result of Roll on each number <source lang=apl inline>n</source> is either
* A real number chosen uniformly at random from between 0 and 1, if n is 0; or
* One of the elements of <source lang=apl inline>⍳n</source> chosen uniformly at random; or
* One of the elements of <source lang=apl inline>⍳n</source> chosen uniformly at random, otherwise.
* A real number between 0 and 1 chosen uniformly at random, if <source lang=apl inline>n</source> 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.
Because [[Iota]] depends on [[index origin]], Roll depends on index origin unless every number in the argument is 0.
Line 29: Line 29:
=== Lessons ===
=== Lessons ===


[https://chat.stackexchange.com/transcript/52405?m=41303127#41303127 APL Cultivation]
* [https://chat.stackexchange.com/transcript/52405?m=41303127#41303127 APL Cultivation]
 
* [https://nbviewer.jupyter.org/github/Dyalog/dyalog-jupyter-notebooks/blob/master/Random%20Numbers.ipynb Jupyter Notebook]


=== Documentation ===
=== Documentation ===


[http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Roll.htm Dyalog]
* [http://help.dyalog.com/latest/Content/Language/Primitive%20Functions/Roll.htm Dyalog]


[http://microapl.com/apl_help/ch_020_020_170.htm APLX]
* [http://microapl.com/apl_help/ch_020_020_170.htm APLX]


J [https://www.jsoftware.com/help/dictionary/d640.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/query NuVoc]
* [https://www.jsoftware.com/help/dictionary/d640.htm J Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/query J NuVoc]

Navigation menu