Created
March 22, 2015 20:52
-
-
Save cshepp/5f457abd9e35820064d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn create-population [gen-size genome-size] | |
"creates a random population of size gen-size, | |
with each genome of size genome-size" | |
(map (fn [x] (vec (unique-random-numbers genome-size))) | |
(range gen-size))) | |
;; from https://clojuredocs.org/clojure.core/rand-int | |
(defn unique-random-numbers [n] | |
"Generates a list of unique random ints between 0 and n" | |
(let [a-set (set (take n (repeatedly #(rand-int n))))] | |
(concat a-set (clojure.set/difference (set (take n (range))) | |
a-set)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment