metosin/malli

Function generators return constant function if seed provided

Open

#1,039 opened on Apr 16, 2024

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Clojure (1,724 stars) (237 forks)batch import
enhancementgeneratorhelp wanted

Description

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]

Contributor guide

Function generators return constant function if seed provided · metosin/malli#1039 | Good First Issue