On 6 September 2017 at 09:50, Cecil Westerhof <cldwester...@gmail.com> wrote:
> > ​I am trying the following throwaway code: > (defn create-pin > ([] (create-pin 8)) > ([n] > {:pre [(<= n 128) > (>= n 4)]} > (let [chars (into [] (concat (range (int \0) (inc (int \9))) (range > (int \A) (inc (int \F)))))] > (println chars) > (reduce str (repeatedly n #(rand-nth chars)))))) > > When calling: > (create-pin 100) > > I get: > [48 49 50 51 52 53 54 55 56 57 65 66 67 68 69 70] > "515367675269685466655167495151494948485155555665705749516870 > 675155706548684865546767695170695066514869707065676954675548 > 665154655470686969555069685167705468495368666948535649515452 > 66554857545648515454" > ​ > ​So it looks like chars is filled correctly, but it only uses 0-9 and not > A-F. So what am I doing wrong?​ > The variable you call "chars" is actually a vector of integers, so you are selecting random integers and joining them together into a string. You could try: (let [chars (mapv char (concat (range (int \0) (inc (int \9))) (range (int \A) (inc (int \F)))))] ...) Ray. -- 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.