      nil
      (nth collection (int (Math/floor (* (Math/random) (count collection))))))))
 
-(defn query
-  "Performs the query against the defined database, and logs the query"
-  [& quer]
-  (log/trace "Performing Query: " quer)
-  (jdb/query db quer))
+(defn get-random-name
+  "Gets a random name from the database. at a specified clearance level"
+  ([]
+   (let [nameMap (get-random-item (query "SELECT * FROM `name` WHERE `name_clearance` = 'U';"))]
+     (str (nameMap :name_first) "-"
+          (nameMap :name_clearance) "-"
+          (nameMap :name_zone))))
+  )
 
 (defn get-sg-by-id
   "Gets service group by sg_id"

     (into [] items) ;; Is done, return a vector
     (recur (dec numb) (conj items (get-news-random-single))))))

(defn get-random-name
  "Gets a random name from the database.
  If supplied with a collision set, tries up to five times to return a name not in that set."
  ([]
   (let [nameMap (get-random-item (query "SELECT * FROM `name` WHERE `name_clearance` = 'U';"))]
     (str (nameMap :name_first) "-"
          (nameMap :name_clearance) "-"
          (nameMap :name_zone))))
  ([collisionSet]
   (get-random-name collisionSet 5))
  ([collisionSet triesRemaining]
   (let [tempName (get-random-name)]
     (if (and (some #{tempName} collisionSet)
              (> triesRemaining 0))
       (recur collisionSet (dec triesRemaining))
       tempName)))
  )

         :subname "//127.0.0.1:3306/hphelper"
         :user "fc"})

(defn query
  "Performs the query against the defined database, and logs the query"
  [& quer]
  (log/trace "Performing Query: " quer)
  (jdb/query db quer))

(def namedItems
  "A map atom with references as keys and named items as values"
  (atom {}))

(defn reset-named-items!
  "Resets the namedItems atom"
  []
  (reset! namedItems {}))

(defn get-name
  "Returns the referenced name from namedItems, or nil if not existing"
  [keyName]
  (get @namedItems keyName))

(defn named-exists?
  "Returns true if the named item already exists in namedItems, else false"
  [refName]
  (if (some #{refName} (vals @namedItems))
    true
    false))

(defn add-name
  "Adds the reference name pair to namedItems, overwriting any previous allocation.
  Returns the added name"
  ([keyRef valName]
   (swap! namedItems assoc keyRef valName)
   valName)
  ([[keyRef valName]]
   (add-name keyRef valName)))

(defn- create-name
  "Creates the name and checks for collisions. After tries runs out just returns the current guess.
  Adds the name to namedItems and returns the new name."
  [nameGen nameRef triesRemaining]
  (let [currentTry (nameGen)]
    (if (and (named-exists? currentTry)
             (> triesRemaining 0))
      (recur nameGen nameRef (dec triesRemaining))
      (add-name nameRef currentTry))))

(defn get-or-create-name
  "Takes a name generation function and a reference, and tries multiple times to create a non-colliding name
  for the reference. If the reference already exists, returns the associated name. After multiple collision attempts
  will simply add the latest try to the map."
  ([nameGen nameRef]
   (if (get-name nameRef)
     (get-name nameRef) ;; It exists, return the name
     (create-name nameGen nameRef 10)))) ;; Otherwise, let's try and make this work

(defn get-random-item
  "Gets a random item from a collection. Returns nil if the collection is empty"
