c-cube / qcheck

QuickCheck inspired property-based testing for OCaml.
https://c-cube.github.io/qcheck/
BSD 2-Clause "Simplified" License
340 stars 37 forks source link

Add warning to Gen.generate* functions #266

Open jmid opened 1 year ago

jmid commented 1 year ago

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.