metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.43k stars 204 forks source link

Function generators return constant function if seed provided #1039

Open frenchy64 opened 2 months ago

frenchy64 commented 2 months ago

This is because we use mg/generate to generate the return value, which always returns the same thing with the same seed.

(repeatedly 10 (mg/generate [:=> :cat :int]))
;=> (-480372 -103 7423 229 83 7937941 -4610 24 -1 21924979)
(repeatedly 10 (mg/generate [:=> :cat :int] {:seed 0}))
;=> (1784201 1784201 1784201 1784201 1784201 1784201 1784201 1784201 1784201 1784201)

;; even for different inputs
(mapv (mg/generate [:=> [:cat :int] :int] {:seed 0}) (range 10))
;=> [1784201 1784201 1784201 1784201 1784201 1784201 1784201 1784201 1784201 1784201]