Skip to content

Instantly share code, notes, and snippets.

@kopos
Created August 21, 2019 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kopos/d4e6a4af5728afb8bc7198132c3b0505 to your computer and use it in GitHub Desktop.
Save kopos/d4e6a4af5728afb8bc7198132c3b0505 to your computer and use it in GitHub Desktop.
Generate alphanumeric random strings of fixed length (starting with one of the 26 letters of the alphabet and rest alnums)
(defn ->letters [s]
(clojure.string/split s #""))
(def first-letter-alphabet
(->letters "qwertyuiopasdfghjklzxcvbnm"))
(def alphabet
(->letters "qwertyuiopasdfghjklzxcvbnm1234567890"))
(defn uid [n]
(clojure.string/join "" (cons
(rand-nth first-letter-alphabet)
(take (dec n) (repeatedly #(rand-nth alphabet))))))
; generate 10 random strings each of length 6
(take 10 (repeatedly #(uid 6))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment