get small ocaml sampling working

This commit is contained in:
NunoSempere 2023-10-14 19:59:56 +01:00
parent dd8a1806bd
commit e9bfd1f2ed
4 changed files with 25 additions and 1 deletions

BIN
ocaml/a.out Executable file

Binary file not shown.

10
ocaml/makefile Normal file
View File

@ -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)

BIN
ocaml/samples.cmi Normal file

Binary file not shown.

View File

@ -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());