2017-09-06 11:00 GMT+02:00 Ray Miller <r...@1729.org.uk>: > 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] >> "51536767526968546665516749515149494848515555566570574951687 >> 067515570654868486554676769517069506651486970706567695467554 >> 866515465547068696955506968516770546849536866694853564951545 >> 266554857545648515454" >> >> 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)))))] >
That does work. I should have looked more carefully, then I would have understand that it was concatenating integers instead of chars. -- 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.