Created
November 4, 2011 17:07
-
-
Save fdaoud/1339865 to your computer and use it in GitHub Desktop.
Clojure - generating a random password
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 random-letter [] | |
(-> (rand-int 26) (+ 97) char)) | |
(defn random-digit [] | |
(rand-int 10)) | |
; for example, (generate-random-password "a1aa1a11") returns something like "z5qr9s42" | |
(defn generate-random-password [spec] | |
(-> #(if (= % \a) (random-letter) (random-digit)) (map spec) (apply str))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment