Knuth's algorithm S: Difference between revisions

m
→‎{{header|REXX}}: changed (back again) the subroutine/function names to conform to the Rosetta Code task requirements.
m (→‎{{header|REXX}}: added/changed whitespace and comments, ordered the subroutines/functions, broke a long statement into smaller ones.)
m (→‎{{header|REXX}}: changed (back again) the subroutine/function names to conform to the Rosetta Code task requirements.)
Line 1,245:
#.=0 /*initialize frequency counter array. */
do trials /*OK, now let's light this candle. */
call create size s_of_n_creator size /*create an initial list of N items. */
 
do gener=0 for 10
call SofN s_of_n gener /*call SofN s_of_n with a single decimal dig*/
end /*gener*/
 
Line 1,269:
do j=e to b by -3; _=insert(',',_,j); end /*j*/; return _
/*────────────────────────────────────────────────────────────────────────────*/
SofNs_of_n: parse arg item; items=items+1 /*get "item", bump the items counter.*/
c=random(1, items) /* [↓] should replace a previous item?*/
if c>size then return /*probability isn't good, so skip it. */
Line 1,275:
return /* ··· item to replace with ITEM.*/
/*────────────────────────────────────────────────────────────────────────────*/
creates_of_n_creator: parse arg item 1 items /*generate ITEM number of items. */
do k=1 for item /*traipse through the first N items. */
!.k=random(0, 9) /*set the Kth item with random digit.*/