]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Random1.scl
(refs #7307) Added features field to SCL module header
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / scl / Random1.scl
1 import "StandardLibrary"
2
3 // Actual program
4
5 """This function returns either 0 or 1 such that
6 the expected value is pi/4"""
7 approximatePi :: () -> <Random> Double
8 approximatePi () = if x*x + y*y < 1 then 1 else 0
9   where
10     x = randomDouble
11     y = randomDouble
12
13 averageOfNRepeats n f = sum [f () | n <- [1..n]] / fromInteger n
14
15 betterApproximatePi () = averageOfNRepeats 1000 approximatePi * 4
16
17 main = withSeed 13 (betterApproximatePi ())
18 --
19 3.068