From 1a5c48a057bdfa09a3ca8e42f235152e189a4b50 Mon Sep 17 00:00:00 2001 From: Sandarr95 Date: Fri, 9 Dec 2016 18:09:06 +0100 Subject: [PATCH 1/2] Added shuffle function using rng from set-random-seed\!, updated readme and project.clj, updated and tested clojure 1.8.0 --- README.md | 4 +++- project.clj | 6 +++--- src/random_seed/core.clj | 10 +++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 76e47da..6d88941 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Supply your own random seed to the clojure.core random functions. (ns example.core (:require [random-seed.core :refer :all]) - (:refer-clojure :exclude [rand rand-int rand-nth])) + (:refer-clojure :exclude [rand rand-int rand-nth shuffle])) (set-random-seed! 888) @@ -20,6 +20,8 @@ Supply your own random seed to the clojure.core random functions. (rand-nth [:a :b :c]) + (shuffle [:a :b :c]) + ## License Copyright © 2015 Trystan diff --git a/project.clj b/project.clj index 1308aa1..69a063c 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,6 @@ -(defproject random-seed "1.0.0" - :description "Copies of rand, rand-int, and rand-nth, except you can specify the seed." +(defproject random-seed "1.0.1" + :description "Copies of rand, rand-int, rand-nth and shuffle, except you can specify the seed." :url "https://www.github.com/trystan/random-seed" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.5.1"]]) + :dependencies [[org.clojure/clojure "1.8.0"]]) diff --git a/src/random_seed/core.clj b/src/random_seed/core.clj index 9f20865..5410147 100644 --- a/src/random_seed/core.clj +++ b/src/random_seed/core.clj @@ -1,5 +1,5 @@ (ns random-seed.core - (:refer-clojure :exclude [rand rand-int rand-nth])) + (:refer-clojure :exclude [rand rand-int rand-nth shuffle])) (defonce rng (new java.util.Random)) @@ -30,3 +30,11 @@ specified in set-random-seed!." [coll] (nth coll (rand-int (count coll)))) + +(defn shuffle + "Return a random permutation of coll. Works like clojure.core/shuffle + except it uses the seed specified in set-random-seed!." + [^java.util.Collection coll] + (let [al (java.util.ArrayList. coll)] + (java.util.Collections/shuffle al rng) + (clojure.lang.RT/vector (.toArray al)))) From 916b392088a2001ce6e80e44e936fa9a104e9842 Mon Sep 17 00:00:00 2001 From: Sandarr95 Date: Fri, 9 Dec 2016 18:10:54 +0100 Subject: [PATCH 2/2] updated leiningen version in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d88941..b09367d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Supply your own random seed to the clojure.core random functions. ## Leiningen - [random-seed "1.0.0"] + [random-seed "1.0.1"] ## Usage