Created
October 20, 2009 00:35
-
-
Save oranenj/213879 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
(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