get small ocaml sampling working
This commit is contained in:
parent
dd8a1806bd
commit
e9bfd1f2ed
BIN
ocaml/a.out
Executable file
BIN
ocaml/a.out
Executable file
Binary file not shown.
10
ocaml/makefile
Normal file
10
ocaml/makefile
Normal 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
BIN
ocaml/samples.cmi
Normal file
Binary file not shown.
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user