Skip to content

Commit

Permalink
Update documentation examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pass Automated Testing Suite authored and Pass Automated Testing Suite committed Apr 29, 2024
1 parent 4db8472 commit 8b89908
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 7 additions & 11 deletions lib/bitgen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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] *)
]}
*)

Expand Down
4 changes: 2 additions & 2 deletions lib/philox.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Philox : sig
SeedSequence.initialize []
|> SeedSequence.spawn 10
|> fst
|> List.map Philox64.initialize
|> List.map Philox4x64.initialize
]} *)

include Common.BITGEN
Expand All @@ -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,
Expand Down

0 comments on commit 8b89908

Please sign in to comment.