Skip to content

Instantly share code, notes, and snippets.

@schaueho
Last active August 29, 2015 14:25
Show Gist options
  • Save schaueho/79c8d19a7304a2994599 to your computer and use it in GitHub Desktop.
Save schaueho/79c8d19a7304a2994599 to your computer and use it in GitHub Desktop.
Generate a random text collection
(defn file2wordlist [wordlistfile]
(-> (slurp wordlistfile)
(str/triml)
(str/split #"\s+")
((partial concat ["." ","]))))
(defn generate-random-text-coll
"Generate a random text collection with nrtexts texts that are up to maxlength long.
Wordlist should be a file with one word per line."
[wordlist nrtexts maxlength]
(let [words (file2wordlist wordlist)
lengths (range 1 maxlength)] ; we don't want 0 length texts
(repeatedly nrtexts
#(repeatedly (rand-nth lengths)
(fn []
(rand-nth words))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment