X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Ftests%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Fscl%2FRandom1.scl;fp=bundles%2Forg.simantics.scl.compiler%2Ftests%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Fscl%2FRandom1.scl;h=66922eadb2f2a41c10e82e06b99592268ed52f54;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/Random1.scl b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/Random1.scl new file mode 100644 index 000000000..66922eadb --- /dev/null +++ b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/scl/Random1.scl @@ -0,0 +1,19 @@ +import "StandardLibrary" + +// Actual program + +"""This function returns either 0 or 1 such that +the expected value is pi/4""" +approximatePi :: () -> Double +approximatePi () = if x*x + y*y < 1 then 1 else 0 + where + x = randomDouble + y = randomDouble + +averageOfNRepeats n f = sum [f () | n <- [1..n]] / fromInteger n + +betterApproximatePi () = averageOfNRepeats 1000 approximatePi * 4 + +main = withSeed 13 (betterApproximatePi ()) +-- +3.068 \ No newline at end of file