Fork me on GitHub

may have been discussed before, but is there a way to install a custom randomness source into spec/gen?

Alex Miller (Clojure team)19:09:32

gen rides on test.check

Alex Miller (Clojure team)19:09:50

test.check does have pluggable randomness, although there are some caveats about it as it's designed to be repeatable

👍 4
🙏 4
Alex Miller (Clojure team)19:09:10

prob best to hit up @gfredericks for the details

Alex Miller (Clojure team)19:09:33

from spec side, the big thing is that stest/check reports the seed it used and accepts a seed as an option to pass along


t.c isn't wired up for that, but the protocol is in place, so currently you could pull it off by monkeypatching random/make-random

wizard 4
👍 4

right. i traced it down to the relevant files, and quickly realized that there are a number of features about the existing random interface that id want to keep in almost every case


What's the motivation?


using the current spec-alpha2.gen whats the best way to create a generator that basically calls a function and returns the value? looking for something like gen/return that evaluates x in each generation


it may sound weird, but im aiming for a generator that produces a fixed number of CSR bytes


Sounds like something better addressed at the generator or spec level, if I'm understanding you


Or is this some kind of security thing where you want High Quality Randomness?


yeah, it definitely is. i was mistaken to think that it would be interesting to aim at the test.check level


gen/fmap is the normal trick for making a generator from an impure function, with all the usual caveats

👍 4

i do want a certain quality of randomness, but more generally im looking for something that would let me (gen/let [x (some-fn-producing-x)] x), but gen/let isnt exposed in spec-alpha2.gen. im using fmap now, but didn’t know if that was the right way:tm:. appreciate the input!


There is no right way, because it circumvents determinism, growth, and shrinking; but spec has generally made theses things a lot murkier


makes total sense. thats what i quickly realized when i was digging into the test.check randomness. those are some really neat files, way above what im trying to do


awesome work!


am i correct in labeling something like this (partial gen/fmap f) a “combinator”?


or would that have a different name


fmap is a generator combinator, and partial is a function combinator; the result is also a generator combinator I suppose

👍 4
🙏 4
🤝 4