Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,38 +1,35 @@
|
|||
/*REXX pgm gens some random #s, shows bin histogram, finds mean & stdDev*/
|
||||
numeric digits 20 /*use twenty digits precision, */
|
||||
showDigs=digits()%2 /* ··· but only show ten digits.*/
|
||||
parse arg size seed . /*allow specification: size, seed*/
|
||||
if size=='' | size==',' then size=100 /*if not specified, then use 100.*/
|
||||
if datatype(seed,'W') then call random ,,seed /*allow seed for RAND.*/
|
||||
#.=0 /*count of numbers in each bin. */
|
||||
do j=1 for size /*generate some random numbers. */
|
||||
@.j=random(0,99999)/100000 /*express as a fraction.*/
|
||||
_=substr(@.j'00',3,1) /*determine which bin it's in, */
|
||||
#._=#._+1 /* ··· and bump its count. */
|
||||
/*REXX pgm gens some random numbers, shows bin histogram, finds mean & stdDev.*/
|
||||
numeric digits 20 /*use twenty decimal digits precision, */
|
||||
showDigs=digits()%2 /* ··· but only show ten decimal digits*/
|
||||
parse arg size seed . /*allow specification: size, and seed.*/
|
||||
if size=='' | size==',' then size=100 /*Not specified? Then use the default.*/
|
||||
if datatype(seed,'W') then call random ,,seed /*allow a seed for RAND BIF.*/
|
||||
#.=0 /*count of the numbers in each bin. */
|
||||
do j=1 for size /*generate some random numbers. */
|
||||
@.j=random(0,99999)/100000 /*express it as a fraction. */
|
||||
_=substr(@.j'00',3,1) /*determine which bin the number is in,*/
|
||||
#._=#._+1 /* ··· and bump its count. */
|
||||
end /*j*/
|
||||
|
||||
do k=0 for 10 /*show a histogram of the bins. */
|
||||
lr='0.'k ; if k==0 then lr='0 ' /*adjust for low range.*/
|
||||
hr='0.'||(k+1); if k==9 then hr='1 ' /* " " high range.*/
|
||||
range=lr"──►"hr' ' /*construct the range. */
|
||||
barPC=right(strip(left(format(100*#.k/size,,2),5)),5) /*comp %*/
|
||||
say range barPC copies('─',format(barPC*1,,0)) /*histo.*/
|
||||
do k=0 for 10 /*show a histogram of the bins. */
|
||||
lr='0.'k ; if k==0 then lr='0 ' /*adjust for the low range.*/
|
||||
hr='0.'||(k+1); if k==9 then hr='1 ' /* " " " high range.*/
|
||||
range=lr"──►"hr' ' /*construct the range. */
|
||||
barPC=right(strip(left(format(100*#.k/size,,2),5)),5) /*comp %.*/
|
||||
say range barPC copies('─',format(barPC*1,,0)) /*histo. */
|
||||
end /*k*/
|
||||
say
|
||||
say 'sample size = ' size; say
|
||||
avg=mean(size) ; say ' mean = ' format(avg,,showDigs)
|
||||
stddev=stddev(size); say ' stddev = ' format(stddev,,showDigs)
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────MEAN subroutine─────────────────────*/
|
||||
mean: parse arg N .; $=0; do m=1 for N; $=$+@.m; end /*m*/
|
||||
return $/n
|
||||
/*──────────────────────────────────STDDEV subroutine───────────────────*/
|
||||
stddev: parse arg N .; $=0; do s=1 for N; $=$+(@.s-avg)**2; end /*s*/
|
||||
return sqrt($/n)
|
||||
/*──────────────────────────────────SQRT subroutine─────────────────────*/
|
||||
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits()
|
||||
numeric digits 11; numeric form; m.=11; p=d+d%4+2
|
||||
parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'E'_%2
|
||||
do j=0 while p>9; m.j=p; p=p%2+1; end
|
||||
do k=j+5 to 0 by -1; if m.k>11 then numeric digits m.k; g=.5*(g+x/g); end
|
||||
numeric digits d; return g/1
|
||||
avg=mean(size) ; say ' mean = ' format(avg,,showDigs)
|
||||
std=stdDev(size); say ' stdDev = ' format(std,,showDigs)
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
mean: parse arg N; $=0; do m=1 for N; $=$+@.m; end; return $/n
|
||||
stdDev: parse arg N; $=0; do s=1 for N; $=$+(@.s-avg)**2; end; return sqrt($/n)
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); i=; m.=9
|
||||
numeric digits 9; numeric form; h=d+6; if x<0 then do; x=-x; i='i'; end
|
||||
parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g*.5'e'_%2
|
||||
do j=0 while h>9; m.j=h; h=h%2+1; end /*j*/
|
||||
do k=j+5 to 0 by -1; numeric digits m.k; g=(g+x/g)*.5; end /*k*/
|
||||
numeric digits d; return (g/1)i /*make complex if X < 0.*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue