Fork me on GitHub
#clojure-spec
<
2019-09-09
>
Nolan19:09:13

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

gfredericks19:09:53

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
Nolan19:09:04

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

gfredericks19:09:18

What's the motivation?

Nolan19:09:07

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

Nolan19:09:45

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

gfredericks19:09:15

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

gfredericks19:09:42

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

Nolan19:09:43

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

gfredericks19:09:05

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

đź‘Ť 4
Nolan19:09:50

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!

gfredericks19:09:41

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

Nolan19:09:34

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

Nolan19:09:50

awesome work!

Nolan19:09:50

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

Nolan19:09:58

or would that have a different name

gfredericks19:09:09

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

đź‘Ť 4
🙏 4
🤝 4