Skip to content

Instantly share code, notes, and snippets.

@rickysaltzer
Created August 8, 2012 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rickysaltzer/3295053 to your computer and use it in GitHub Desktop.
Save rickysaltzer/3295053 to your computer and use it in GitHub Desktop.
random state and words generator
(ns honeycomb.core
(:gen-class)
(:require [clojure.string :as string]))
; Reads a file into an array (split by newline / \n)
(defn file->array
[filename]
(string/split-lines (slurp filename)))
; Some definitions of random arrays of STUFF
;States
(def states
(file->array "states.txt"))
; Words
(def words
(file->array "words.txt"))
; Grab a random element out of a PersistentVector
(defn grab
[v]
(nth v (rand-int (count v))))
; Generate n rows of data
; provide n (number of rows to generate)
; datesets (arbitrary amount of datsets to grab random elements from)
(defn seq-rows
[n & sets]
(map (fn [x]
(map grab sets)) (range n)))
(defn to->csv
[n]
(map (fn [x]
(reduce #(str %1 "," %2) x)) n))
(defn -main
"I don't do a whole lot."
[n & args]
(doseq
[x (seq-rows (Integer/parseInt n) states words words)] (println x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment