Chouser's solution works well, but I found that you can end up with an empty string sometimes or never getting the maxlength that you passed in.
1:2 user=> (take 3 (seq-of-rand-strings 10)) ("ngene" "" "dwlbzndqx") I added an inc before calling the take and that clears things up. (defn seq-of-rand-strings [maxlength] (repeatedly (fn [] (apply str (take (inc (rand-int maxlength)) (repeatedly #(char (+ (int \a) (rand-int 26))))))))) On Mon, Jan 12, 2009 at 1:38 AM, GS <gsincl...@gmail.com> wrote: > > > > (defn seq-of-rand-strings [maxlength] > > (repeatedly (fn [] > > (apply str (take (rand-int maxlength) > > (repeatedly #(char (+ (int \a) (rand-int 26))))))))) > > > > user=> (take 3 (seq-of-rand-strings 10)) > > ("kae" "xwuwyp" "xa") > > Thanks Chouser. I learned some useful and interesting things from > your reply. I was unaware of 'char and 'repeatedly. > > Gavin > > > --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---