Next regular post

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet odio imperdiet, malesuada ex eu, consectetur enim. In eget blandit massa, imperdiet pretium eros. Proin feugiat elementum libero id condimentum. Duis varius dignissim eros, sit amet faucibus libero ultricies sed. Pellentesque massa tortor, blandit et est a, facilisis consequat turpis. Curabitur id accumsan quam. Integer egestas accumsan ullamcorper. Vivamus efficitur justo enim, sit amet condimentum lectus interdum sit amet. Aliquam aliquam auctor tellus quis vulputate. Fusce porttitor augue et nunc elementum consectetur. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In auctor faucibus enim at ornare. Mauris tristique nulla id dolor tincidunt, non semper nisi auctor. Nullam eu nulla at tortor tempor molestie a aliquet quam.

Test image

(ns mandelbrot.loremipsum
  (:require [clojure.string :as s]))

(defn rand-word
  "Generates a random word based on what letters appeared at what index.
  If the index doesn't exist, it pulls a random character from the sample-text."
  [length pos-map sample-text]
  (apply str
    (for [i (range length)]
      (rand-nth (get pos-map i sample-text)))))

(defn safe-rand-word
  "Helper that loops while the produced input is in the exclusion set.
  May get stuck if the sample size is too small."
  [length pos-map sample-text exclusion-set]
  (loop []
    (let [word (rand-word length pos-map sample-text)]
      (if (exclusion-set word)

(defn rand-word-len
  "Generates a length based on avg-len +/- an amount in 
  the (range (- deviation) deviation))."
  [avg-len deviation]
  (+ avg-len
     (rand-nth (range (- deviation) deviation))))

(defn pos-letters
  "Records what characters occured at each index of each word."
  ; A two dimensional reduction.
  ; The inner reduction takes an existing pos-map, and updates it with information about the word
  ; The outer reduction combines all the word pos-maps together.
  (reduce (fn [pos-map word]
            (reduce (fn [acc [i chr]]
                      (update acc i #(if % (conj % chr)

                    ; Maps with the index of each letter
                    (map vector (range) word)))

(defn gobbly [n-chars sample-text]
  (let [; Split the text into words, then place the words into a set
        ;  to ensure that they aren't generated.
        words (s/split sample-text #"\s")
        word-set (into #{} words)

        stripped-text (s/replace sample-text #"[,.?!]" "")

        ; Figure out the average word length, then calculate how much
        ;  deviation should be allowed.
        avg-word-len (/ (count sample-text) (count words))
        length-deviation (/ avg-word-len 4)

        ; Find which characters appear at which positions
        pos-map (pos-letters words)]

    ; Generate n-chars many characters by...
    (doseq [n (range n-chars)]
      ; ...printing a space, then a randomly generated word.
      (print ""
        (safe-rand-word (rand-word-len avg-word-len length-deviation)


Written by
Later article
Image test
Older article
Something Old