Skip to content

Instantly share code, notes, and snippets.

@cshepp
Created March 22, 2015 20:52
Show Gist options
  • Save cshepp/5f457abd9e35820064d0 to your computer and use it in GitHub Desktop.
Save cshepp/5f457abd9e35820064d0 to your computer and use it in GitHub Desktop.
(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