From 8322b2b2018aa00100bd99ab7946d76787eed028 Mon Sep 17 00:00:00 2001 From: "Ryan M. Moore" Date: Wed, 3 May 2023 15:26:49 -0400 Subject: [PATCH 1/2] Add docs about seeding random generator --- src/Iter.mli | 6 +++++- src/IterLabels.mli | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Iter.mli b/src/Iter.mli index 28be7a6..744fb25 100644 --- a/src/Iter.mli +++ b/src/Iter.mli @@ -705,7 +705,11 @@ module Map : sig module Make (V : Map.OrderedType) : S with type key = V.t end -(** {1 Random iterators} *) +(** {1 Random iterators} + + Random iterators use [Random.int], [Random.float], [Random.bool], + etc., under the hood, so they will respect seeding of the random + generator in the usual way. *) val random_int : int -> int t (** Infinite iterator of random integers between 0 and diff --git a/src/IterLabels.mli b/src/IterLabels.mli index 65a566b..6dad4ab 100644 --- a/src/IterLabels.mli +++ b/src/IterLabels.mli @@ -674,7 +674,11 @@ module Map : sig module Make (V : Map.OrderedType) : S with type key = V.t end -(** {2 Random iterators} *) +(** {2 Random iterators} + + Random iterators use [Random.int], [Random.float], [Random.bool], + etc., under the hood, so they will respect seeding of the random + generator in the usual way. *) val random_int : int -> int t (** Infinite iterator of random integers between 0 and From b65be73022667be19fbdcaf7351cd7d203f2fb5b Mon Sep 17 00:00:00 2001 From: "Ryan M. Moore" Date: Wed, 3 May 2023 18:34:24 -0400 Subject: [PATCH 2/2] Add seeding section with example --- src/Iter.mli | 26 ++++++++++++++++++++++---- src/IterLabels.mli | 26 ++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/Iter.mli b/src/Iter.mli index 744fb25..e833fff 100644 --- a/src/Iter.mli +++ b/src/Iter.mli @@ -705,11 +705,9 @@ module Map : sig module Make (V : Map.OrderedType) : S with type key = V.t end -(** {1 Random iterators} +(** {1 Random iterators} *) - Random iterators use [Random.int], [Random.float], [Random.bool], - etc., under the hood, so they will respect seeding of the random - generator in the usual way. *) +(** {2 Generating} *) val random_int : int -> int t (** Infinite iterator of random integers between 0 and @@ -749,6 +747,26 @@ val sample : int -> 'a t -> 'a array It returns an array of size [min (length seq) n]. @since 0.7 *) +(** {2 Seeding} + + Random iterators use [Random.int], [Random.float], [Random.bool], + etc., under the hood, so they will respect seeding of the random + generator in the usual way. I.e., if you do not initialize the + random generator with one of [Random.init], [Random.full_init], or + [Random.self_init] before calling these functions, they will yield + the same values across seperate invocations of your program. + + Example: + + {[ + (* Ensure a fresh random seed each time the program is executed. *) + let () = Random.self_init () + + (* Generate random values. *) + let l = Iter.random_int 1000 |> Iter.take 3 |> Iter.to_list + ]} + *) + (** {1 Infix functions} *) module Infix : sig diff --git a/src/IterLabels.mli b/src/IterLabels.mli index 6dad4ab..4d06a9a 100644 --- a/src/IterLabels.mli +++ b/src/IterLabels.mli @@ -674,11 +674,9 @@ module Map : sig module Make (V : Map.OrderedType) : S with type key = V.t end -(** {2 Random iterators} +(** {2 Random iterators} *) - Random iterators use [Random.int], [Random.float], [Random.bool], - etc., under the hood, so they will respect seeding of the random - generator in the usual way. *) +(** {3 Generating} *) val random_int : int -> int t (** Infinite iterator of random integers between 0 and @@ -718,6 +716,26 @@ val sample : n:int -> 'a t -> 'a array It returns an array of size [min (length seq) n]. @since 0.7 *) +(** {3 Seeding} + + Random iterators use [Random.int], [Random.float], [Random.bool], + etc., under the hood, so they will respect seeding of the random + generator in the usual way. I.e., if you do not initialize the + random generator with one of [Random.init], [Random.full_init], or + [Random.self_init] before calling these functions, they will yield + the same values across seperate invocations of your program. + + Example: + + {[ + (* Ensure a fresh random seed each time the program is executed. *) + let () = Random.self_init () + + (* Generate random values. *) + let l = Iter.random_int 1000 |> Iter.take 3 |> Iter.to_list + ]} + *) + (** {2 Infix functions} *) module Infix : sig