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