Anonymous user
Probabilistic choice: Difference between revisions
→{{header|REXX}}: added/changed comments and whitespace, used a template for the output, added a comment to the REXX section header, optimized the generating of the trials.
m (→{{header|Ring}}: flagged as needing improvement.) |
(→{{header|REXX}}: added/changed comments and whitespace, used a template for the output, added a comment to the REXX section header, optimized the generating of the trials.) |
||
Line 2,690:
=={{header|REXX}}==
Note: REXX can generate random numbers up to 100,000.
<lang rexx>/*REXX program displays results of probabilistic choices, gen random #s per probability.*/
parse arg trials digs seed . /*obtain the optional arguments from CL*/
Line 2,696 ⟶ 2,697:
if datatype(seed, 'W') then call random ,,seed /*allows repeatability for RANDOM nums.*/
numeric digits digs /*use a specific number of decimal digs*/
names= 'aleph beth gimel daleth he waw zayin heth ───totals───►'
z=words(names); #=z - 1 /*#≡the number of actual/useable names.*/
$=0
do n=1 for #; prob.n=1 / (n+4); if n==# then prob.n= 1759 / 27720
$=$ + prob.n; Hprob.n=prob.n * HI
end /*n*/
prob.z=$ /*define the value of the ───totals───.*/
@.z=trials /*define the last counter of " " */
do j=1 for trials; r=random(
do k=1 for # /*for each cell, compute percentages. */
if r<=Hprob.k then
end /*k*/
end /*j*/
w=digs +
d=4 + max( length(trials), length('count') ) /* [↓] display a formatted top header.*/
say center('name',15,
do
say ' ' left( word(names,
left( format( prob.
left( format(
if
end /*
/*stick a fork in it, we are all done.*/</lang>
<pre>
═════name══════ ═══count═══ ══════target %═══════ ══════actual %═══════
aleph
beth
gimel
daleth
he
waw
zayin
heth
═══════════════ ═══════════ ═════════════════════ ═════════════════════
───totals───► 1000000 100 100
|