How can I get a sequence of random numbers by providing a seed in clojure.test.check?
what sort of numbers?
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))
thanks
if you are using this for PBT I would probably recommend using generators instead, or would be interested in why you can't
I would like to use this for some graphical algorithm which needs random numbers, but I want to make it deterministic
okay cool; yeah if it's not for testing then using the RNG directly is perfectly fine
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?
or do I have to convert longs to a range myself, which is also possible
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
yeah, cool
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?
I guess I can calculate this up front
you can make an infinite lazy seq
there's a private(?) function in generators.cljc
that does this
lazy-random-states
or something to that effect
Cool: https://clojure.github.io/test.check/clojure.test.check.generators.html#var-lazy-random-states
So this would be it right? (take 2 (map random/rand-long (gen/lazy-random-states (random/make-random 2))))
yep