Hi Cecil - welcome back! This would be perfect to test using the new clojure.spec. I can't give you any advice on the specifics as I have yet to break into it myself, but the properties of this function are crying out for generative testing.
Cecil Westerhof writes: > I want to start using Clojure again. I made the following simple function > to generate a PIN: > (defn create-pin > ([] (create-pin 8)) > ([n] > (let [chars (map char (range (int \0) (inc (int \9))))] > (reduce str (repeatedly n #(rand-nth chars)))))) > > So far so good. But I want to improve a little. > > I think n should at least be four, but not greater as 16. What is the > Clojure way to do this? > > The next step is that I want to use hexadecimal numbers. So I should use > (range (int \0) (inc (int \9))) combined with (range (int \A) (inc (int > \F))). > How would I do that? > > Is there anything I should do differently? > > Of-course I make a general function that is then called from create-pin and > create-pin-hex. > > -- > Cecil Westerhof -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.