diff --git a/ocaml/a.out b/ocaml/a.out new file mode 100755 index 00000000..f7e94012 Binary files /dev/null and b/ocaml/a.out differ diff --git a/ocaml/makefile b/ocaml/makefile new file mode 100644 index 00000000..2aa5e20d --- /dev/null +++ b/ocaml/makefile @@ -0,0 +1,10 @@ +# Compiler +CC=ocamlopt +# ocamlopt: platform-specific, faster +# ocamlc: platform-independent intermediate representation, run with ocamlrun + +# Main file +SRC=samples.ml + +build: $(SRC) + $(CC) $(SRC) diff --git a/ocaml/samples.cmi b/ocaml/samples.cmi new file mode 100644 index 00000000..3d9846c6 Binary files /dev/null and b/ocaml/samples.cmi differ diff --git a/ocaml/samples.ml b/ocaml/samples.ml index 5201e324..2c432d3b 100644 --- a/ocaml/samples.ml +++ b/ocaml/samples.ml @@ -1 +1,15 @@ -print_endline "Hello world";; +(* Constants *) +let pi = acos (-1.) + +(* Basic samplers *) +let sampleZeroToOne () : float = Random.float 1.0 +let sampleStandardNormal (): float = + let u1 = sampleZeroToOne () in + let u2 = sampleZeroToOne () in + let z = sqrt(-2.0 *. log(u1)) *. sin(2.0 *. pi *. u2) in + z + +let () = + Random.init 1; + Printf.printf "%f\n" (sampleZeroToOne()); + Printf.printf "%f\n" (sampleZeroToOne());