diff --git a/README.md b/README.md index 3cc6c2f..e7522f1 100644 --- a/README.md +++ b/README.md @@ -32,19 +32,15 @@ SeedSequence.generate_64bit_state 4 seedseq |> Array.map Uint64.to_string Below is an example of using an initialized `PCG64` bitgenerator to generate 10 random floats: ```ocaml -let rec get_floats n t acc = match n <= 0 with - | true -> List.rev acc, t - | false -> match PCG64.next_double t with - | u, t' -> get_floats (n - 1) t' (Float.to_string u :: acc) -in -get_floats 10 rng [] |> fst -(** an example output from the above call would be: - - : string list = - ["0.913894299701"; "0.792148446413"; "0.949364012916"; "0.143892066375"; - "0.70297277417"; "0.933940885237"; "0.338831577483"; "0.460820972876"; - "0.61424098101"; "0.38294818093"] *) +let func t = let u, t' = PCG64.next_double t in Some (u, t') in +Seq.unfold func rng |> Seq.take 10 |> List.of_seq +(* - : float list = + [0.227336022467169663; 0.316758339709752867; 0.797365457332734118; + 0.676254670750974562; 0.391109550601909; 0.332813927866384529; + 0.598308753587189823; 0.186734185603713354; 0.672756044014621302; + 0.941802865269937173] *) ``` -Supported bitgenerators include: `PCG64`, `Philox64`, `Xoshiro256`, `ChaCha` and `SFC64`. +Supported bitgenerators include: `PCG64`, `Philox4x64`, `Xoshiro256`, `ChaCha` and `SFC64`. ## Empirical Randomness Testing Running the test suite provided by [TestU01][6] on the supported generators is supported. diff --git a/lib/bitgen.ml b/lib/bitgen.ml index 739b791..a8e9276 100644 --- a/lib/bitgen.ml +++ b/lib/bitgen.ml @@ -14,19 +14,15 @@ {@ocaml[ open Bitgen open Stdint - - let rec generate_10 i t acc = match i >= 10 with - | true -> List.rev acc, t - | false -> match PCG64.next_double t with - | v, t' -> generate_10 (i + 1) t' (v :: acc) - let rng = SeedSequence.initialize [] |> PCG64.initialize in - generate_10 0 rng [] |> fst + let rng = SeedSequence.initialize [Uint128.of_int 12345] |> PCG64.initialize in + let func t = let u, t' = PCG64.next_double t in Some (u, t') in + Seq.unfold func rng |> Seq.take 10 |> List.of_seq (* - : float list = - [0.227336022467169663; 0.316758339709752867; 0.797365457332734118; - 0.676254670750974562; 0.391109550601909; 0.332813927866384529; - 0.598308753587189823; 0.186734185603713354; 0.672756044014621302; - 0.941802865269937173] *) + [0.227336022467169663; 0.316758339709752867; 0.797365457332734118; + 0.676254670750974562; 0.391109550601909; 0.332813927866384529; + 0.598308753587189823; 0.186734185603713354; 0.672756044014621302; + 0.941802865269937173] *) ]} *) diff --git a/lib/philox.ml b/lib/philox.ml index 74486f6..c349c3e 100644 --- a/lib/philox.ml +++ b/lib/philox.ml @@ -32,7 +32,7 @@ module Philox : sig SeedSequence.initialize [] |> SeedSequence.spawn 10 |> fst - |> List.map Philox64.initialize + |> List.map Philox4x64.initialize ]} *) include Common.BITGEN @@ -43,7 +43,7 @@ module Philox : sig initiale state of the generator's [key].*) val jump : t -> t - (** [jump t] is equivalent to {m 2^{128}} calls to {!Philox64.next_uint64}. *) + (** [jump t] is equivalent to {m 2^{128}} calls to {!Philox4x64.next_uint64}. *) val advance : uint64 * uint64 * uint64 * uint64 -> t -> t (** [advance n] Advances the generator forward as if [n] draws have been made,