Fork me on GitHub
#test-check
<
2017-11-10
>
borkdude12:11:46

How can I get a sequence of random numbers by providing a seed in clojure.test.check?

gfredericks12:11:31

what sort of numbers?

gfredericks12:11:32

if you want to just use the raw RNG code it's pretty easy (map random/rand-long (random/split-n (random/make-random seed) 500))

gfredericks12:11:23

if you are using this for PBT I would probably recommend using generators instead, or would be interested in why you can't

borkdude12:11:39

I would like to use this for some graphical algorithm which needs random numbers, but I want to make it deterministic

gfredericks12:11:16

okay cool; yeah if it's not for testing then using the RNG directly is perfectly fine

borkdude16:11:48

I’m looking for examples online but can’t find it. Is there a way that I can express that I want ints in a range using the generators + a custom seed?

borkdude16:11:01

or do I have to convert longs to a range myself, which is also possible

gfredericks16:11:42

the rng only generates raw uniform longs; if your range isn't close to 64 bits, I'd just use mod to get what you want

borkdude16:11:03

Is there a way to get around the fixed size 500 in (map (comp #(mod % 1000) r/rand-long) (r/split-n (r/make-random 2) 500)) so I can get a lazy sequence of these numbers or do I need to specify this up front always?

borkdude16:11:30

I guess I can calculate this up front

gfredericks16:11:07

you can make an infinite lazy seq

gfredericks16:11:19

there's a private(?) function in generators.cljc that does this

gfredericks16:11:24

lazy-random-states or something to that effect

borkdude16:11:39

So this would be it right? (take 2 (map random/rand-long (gen/lazy-random-states (random/make-random 2))))