One of n lines in a file: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments.
(Add Forth)
m (→‎{{header|REXX}}: added/changed whitespace and comments.)
Line 1,569:
 
=={{header|REXX}}==
<lang rexx>/*REXX pgmprogram simulates reading a ten-line file and make randomness counts.*/
N=10 /*the number of lines in pseudo-file. */
#@.=0 /*zero all the (ten) "buckets". */
do 1000000 /*perform main loop one million trialstimes. */
?=1
do k=1 for N /*N is the #number of lines in the file*/
if random(0,99999) / 100000 < 1/k then ?=k /*the critera.criteria*/
end /*k*/
#@.?=#@.?+1 /*addbump itthe tocount thein bucketa counters.particular bucket*/
end /*1000000*/
 
do j=1 for N /*display the randomness counts (buckets). */
say "number of times line" right(j,2) "was selected:" right(#@.j,9)
end /*j*/
/*stick a fork in it, we're all done. */</lang>
'''output'''
<pre>
<pre style="overflow:scroll">
number of times line 1 was selected: 99752
number of times line 2 was selected: 100060