Random numbers: Difference between revisions

→‎{{header|Scala}}: migrate to Scala 2.13
No edit summary
(→‎{{header|Scala}}: migrate to Scala 2.13)
Line 2,145:
<lang scala>List.fill(1000)(1.0 + 0.5 * scala.util.Random.nextGaussian)</lang>
===Academic===
<lang scala>val distrubution = {
object RandomNumbers extends App {
def randomNormal = 1.0 + 0.5 * scala.util.Random.nextGaussian
 
val distribution: LazyList[Double] = {
def normalDistribution(a: Double): Stream[Double] = a #:: normalDistribution(randomNormal)
def randomNormal: Double = 1.0 + 0.5 * scala.util.Random.nextGaussian
 
def normalDistribution(a: Double): LazyList[Double] = a #:: normalDistribution(randomNormal)
 
normalDistribution(randomNormal)
/*
}
* Let's test it
 
*/
/*
* Let's test it
*/
def calcAvgAndStddev[T](ts: Iterable[T])(implicit num: Fractional[T]): (T, Double) = {
val mean: T =
Line 2,161 ⟶ 2,164:
 
// Root of mean diffs
val stdDev = Math.sqrt(ts.map { x =>
val diff = num.toDouble(num.minus(x, mean))
diff * diff
Line 2,169 ⟶ 2,172:
}
 
println(calcAvgAndStddev(distrubutiondistribution.take(1000))) // e.g. (1.0061433267806525,0.5291834867560893)</lang>
</lang>
 
=={{header|Scheme}}==
92

edits