2017-09-06 10:13 GMT+02:00 Cecil Westerhof <cldwester...@gmail.com>:

> Answering my own question. ;-)
>
> 2017-09-06 9:58 GMT+02:00 Cecil Westerhof <cldwester...@gmail.com>:
>
>> 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?
>>
>
> ​    (concat (range (int \0) (inc (int \9))) (range (int \A) (inc (int
> \F))))
> ​
>
> ​By the way. I am using a lazy sequence here. Could it be updated with
> using a vector when creating very long strings, or is that not a
> significant performance increase?​
>

​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]
"51536767526968546665516749515149494848515555566570574951687067515570654868486554676769517069506651486970706567695467554866515465547068696955506968516770546849536866694853564951545266554857545648515454"
​
​So it looks like chars is filled correctly, but it only uses 0-9 and not
A-F. So what am I doing wrong?​


-- 
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.

Reply via email to