Impressum/Kontaktparent nodes: implemented functions

Deal

testAplDeal
| random10 rndList list bingo |
"http://www.microapl.co.uk/apl_help/ch_020_020_180.htm"

"range aplDeal: request"

"Generates as many random numbers as are specified in the request argument from the first N numbers starting at 1, where N is specified in the range argument. Each number generated is unique; that is to say there are no repetitions. The left and right arguments must be simple numeric scalars or one-element vectors."

"A request for 10 unique random numbers in the range 1 to 100."
random10 := 100 asApl aplDeal: 10.

self assert: random10 size = 10.
rndList := random10 asObject.
self assert:(rndList allSatisfy:[:each| each >= 1 and: [each <=100]]).
self assert:(rndList allSatisfy:[:each| 1 = (rndList occurrencesOf:each)]).


"3 random numbers between 1 and 10 are put in LIST"
list := 10 asApl aplDeal:3.
rndList := list asObject.
self assert:(rndList allSatisfy:[:each| each between:1 and:10]).
self assert:(rndList allSatisfy:[:each| 1 = (rndList occurrencesOf:each)]).

"16 random numbers between 1 and 100 are put into a 4-by-4 matrix called BINGO"
bingo := (100 asApl aplDeal: 16) aplReshape:#(4 4).
rndList := bingo asObject.
self assert:(rndList allSatisfy:[:each| each between:1 and:100]).
self assert:(rndList allSatisfy:[:each| 1 =( rndList occurrencesOf:each)]).

"A request for 4 unique integers in the range 1 to 3 causes an error"
self should:[3 asApl aplDeal:4] raise: AplDomainError.


"Note: The AplVector setting randomLink contains a seed value used to generate random numbers. To generate the same number(s) on two occasions, set randomLink to the same value before each use of ?."

AplVector randomLink:12345.
self assert: #(967 8341 9478 359 116) asApl = (10000 asApl aplDeal:5).
self assert: (#(97 834 948 36 12) asApl = (10000 asApl aplDeal:5)) not.

AplVector randomLink:12345.
self assert: #(967 8341 9478 359 116) asApl = (10000 asApl aplDeal:5).
self assert: (#(97 834 948 36 12) asApl = (10000 asApl aplDeal:5)) not.