This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-10
Channels
- # aleph (4)
- # aws (2)
- # bangalore-clj (2)
- # beginners (84)
- # boot (25)
- # cider (3)
- # cljsrn (3)
- # clojure (57)
- # clojure-italy (5)
- # clojure-losangeles (3)
- # clojure-russia (7)
- # clojure-spec (18)
- # clojure-uk (29)
- # clojurescript (90)
- # cursive (11)
- # data-science (68)
- # datascript (2)
- # datomic (25)
- # duct (3)
- # fulcro (13)
- # graphql (7)
- # immutant (1)
- # jobs (1)
- # leiningen (12)
- # lumo (1)
- # off-topic (51)
- # om (43)
- # onyx (15)
- # parinfer (10)
- # pedestal (4)
- # re-frame (7)
- # reagent (42)
- # ring-swagger (42)
- # rum (1)
- # shadow-cljs (172)
- # spacemacs (10)
- # specter (4)
- # sql (4)
- # test-check (19)
- # unrepl (54)
- # yada (3)
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))
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?
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
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?
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