Created
August 21, 2019 11:44
-
-
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)
This file contains 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
(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