I don't think anyone is actually using this, but just in case: if you need a common Clojure/ClojureScript API for random number generation, you should use the splittable PRNG implemented for test.check (clojure.test.check.random
). I implemented pprng solely to enable double-check, and its deprecation leaves this project without purpose.
portable pseudo-random number generators for Clojure/ClojureScript
Add to your Leiningen project.clj
:
[com.cemerick/pprng "0.0.3"]
NOTE pprng does not use cryptographically-secure random number generators, either on Clojure/JVM or ClojureScript/JS. DO NOT use this library to help implement or inform any cryptographically-sensitive algorithm.
user=> (require '[cemerick.pprng :as rng])
nil
;; get a new RNG, optionally providing a seed
user=> (def rng (rng/rng))
#'user/rng
;; obtain values from it...
user=> (rng/int rng)
-1170105035
user=> (rng/int rng 1000)
267
user=> (rng/boolean rng)
false
user=> (rng/double rng)
0.6832234717598454
;; obtain the seed that was used to create it originally, if necessary
user=> (rng/seed rng)
1372270869019
Ping cemerick
on freenode irc or
twitter if you have questions or would
like to contribute patches.
Copyright ©2013-* Chas Emerick and other contributors.
Distributed under the Eclipse Public License, the same as Clojure.
Please see the epl-v10.html
file at the top level of this repo.