Skip to content

Instantly share code, notes, and snippets.

@oranenj
Created October 20, 2009 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oranenj/213879 to your computer and use it in GitHub Desktop.
Save oranenj/213879 to your computer and use it in GitHub Desktop.
(def *vowels* (vec "aeiou"))
(def *consonants* (vec "qwrtpsdgfhjklzxcvbnm"))
(defn seq-of-random
"produces a seq of elements from v at random"
[v]
(repeatedly #(nth v (rand-int (count v)))))
(defn drop-randomly
"drop elements from sequence at random"
[seq]
(filter (fn [_] (zero? (rand-int 2))) seq))
(defn random-chars []
"produces an infinite sequence of random characters"
(drop-randomly
(interleave (seq-of-random *vowels*)
(seq-of-random *consonants*))))
(defn words [n]
"produces an infinite sequence of random 'words' of length n"
(map (partial apply str) (partition n (random-chars))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment