Anonymous user
Probabilistic choice: Difference between revisions
m
→{{header|REXX}}: changed comments and whitespace.
(Added Wren) |
m (→{{header|REXX}}: changed comments and whitespace.) |
||
Line 2,692:
=={{header|REXX}}==
Note: REXX can generate random numbers up to a range of 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*/
if trials=='' | trials=="," then trials=
if digs=='' | digs=="," then digs=
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───►' /*names of the cells.*/
z= words(names);
$=
do n=1 for #; prob.n= 1 / (n+4); if n==# then prob.n= 1759 / 27720
$= $ + prob.n; Hprob.n= prob.n *
end /*n*/
prob.z=
@.=
@.z=
do j=1 for trials; r= random(
do k=1 for #
if r<=Hprob.k then @.k= @.k + 1
end /*k*/
end /*j*/
_= '═' /*_:
w= digs + 6
d= 4 + max( length(trials), length('count') )
say center('name',15,_) center('count',d,_) center('target %',w,_) center('actual %',w,_)
do cell=1 for z /*display each of the cells and totals.*/
say ' ' left( word(names, cell), 13)
left( format( prob.cell * 100, d), w-2),
left( format( @.cell/trials * 100, d), w-2)
|