Created
August 8, 2012 13:32
-
-
Save rickysaltzer/3295053 to your computer and use it in GitHub Desktop.
random state and words generator
This file contains hidden or 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
(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