(let [chars "0123456789ABCDEF"] ...) Replace `reduce` with `apply` to get the performance benefit of using a string builder behind the scenes.
On Wed, Sep 6, 2017 at 12:58 AM, Cecil Westerhof <cldwester...@gmail.com> wrote: > 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. > -- 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.