tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
55
Task/Random-numbers/NetRexx/random-numbers.netrexx
Normal file
55
Task/Random-numbers/NetRexx/random-numbers.netrexx
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
import java.math.BigDecimal
|
||||
import java.math.MathContext
|
||||
|
||||
-- prologue
|
||||
numeric digits 20
|
||||
|
||||
-- get input, set defaults
|
||||
parse arg dp mu sigma ec .
|
||||
if mu = '' | mu = '.' then mean = 1.0; else mean = mu
|
||||
if sigma = '' | sigma = '.' then stdDeviation = 0.5; else stdDeviation = sigma
|
||||
if dp = '' | dp = '.' then displayPrecision = 1; else displayPrecision = dp
|
||||
if ec = '' | ec = '.' then elements = 1000; else elements = ec
|
||||
|
||||
-- set up
|
||||
RNG = Random()
|
||||
numberList = java.util.List
|
||||
numberList = ArrayList()
|
||||
|
||||
-- generate list of random numbers
|
||||
loop for elements
|
||||
rn = mean + stdDeviation * RNG.nextGaussian()
|
||||
numberList.add(BigDecimal(rn, MathContext.DECIMAL128))
|
||||
end
|
||||
|
||||
-- report
|
||||
say "Mean: " mean
|
||||
say "Standard Deviation:" stdDeviation
|
||||
say "Precision: " displayPrecision
|
||||
say
|
||||
drawBellCurve(numberList, displayPrecision)
|
||||
|
||||
return
|
||||
|
||||
-- -----------------------------------------------------------------------------
|
||||
method drawBellCurve(numberList = java.util.List, precision) static
|
||||
Collections.sort(numberList)
|
||||
val = BigDecimal
|
||||
lastN = ''
|
||||
nextN = ''
|
||||
loop val over numberList
|
||||
nextN = Rexx(val.toPlainString()).format(5, precision)
|
||||
select
|
||||
when lastN = '' then nop
|
||||
when lastN \= nextN then say lastN
|
||||
otherwise nop
|
||||
end
|
||||
say '*\-'
|
||||
lastN = nextN
|
||||
end val
|
||||
say lastN
|
||||
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue