Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warning to Gen.generate* functions #266

Open
jmid opened this issue Nov 10, 2022 · 0 comments
Open

Add warning to Gen.generate* functions #266

jmid opened this issue Nov 10, 2022 · 0 comments

Comments

@jmid
Copy link
Collaborator

jmid commented Nov 10, 2022

The two Gen.generate* functions are very handy at top-level, e.g., to trigger generation without going through the test-and-check-property loop:

  val generate : ?rand:Random.State.t -> n:int -> 'a t -> 'a list
  (** [generate ~n g] generates [n] instances of [g]. *)

  val generate1 : ?rand:Random.State.t -> 'a t -> 'a
  (** [generate1 g] generates one instance of [g]. *)

However, because they use a default, self-initializing Random.State they should not be combined with the other Gen combinators to form a larger generator - as the self-initialization breaks reproducability completely (I've seen this happen more than once):

  let generate ?(rand=Random.State.make_self_init()) ~n g =
    list_repeat n g rand

  let generate1 ?(rand=Random.State.make_self_init()) g = g rand

I suggest we add a big red warning flag to their documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant