Clojure 1.2 has a shuffle function. If you're using 1.1, you can just cop the 1.2 implementation.
On Jul 21, 1:18 pm, Ryan Waters <[email protected]> wrote: > http://gist.github.com/484747 > > - - - > > My sad little program has a number of issues and I would welcome > suggestions on any aspect of it. I come from an imperative > programming background and clojure is my first experience with a > functional or lisp language. > > I'd like to take a list of things (really, a vector) and randomly add > items of that list to another list. I chose to work with vectors > because clojure is efficient at adding things their ends and because I > can address their consistent ordering with an index. > > Issues: > > 1) Idiomatic: please point out anything that looks generally awkward > or otherwise less than ideal for clojure (and suggest an alternative) > : ) For example, in my loop I rebind symbols to themselves and have > received mixed advice on IRC as to whether it's appropriate to do > that. > > 2) Transients: For speed and because I don't care about the > intermediate values of the vectors, I'd like to use them. I was able > to easily work with the transient vector 'random-ips' but receive an > error when trying to wrap the vector 'ordered-ips' in a transient: > "Exception in thread "main" java.lang.ClassCastException: > clojure.lang.PersistentVector$TransientVector cannot be cast to > clojure.lang.IPersistentVector (gen_ips.clj:36)" > > 3) Overall speed: it's abysmal but I don't blame Clojure. It's either > because I'm Doing It Wrong or what I'm doing is simply expensive in a > big O notation sort of way. I'm trying to randomly order 1.1 million > strings. > > 4) Clojure side-gripe: I wish it were easier to mix clojure's > different 'types': vectors, lazy sequences, etc. It's probably an > ignorance thing on my part but, for what I know right now, I find > using different macros with all the different return types > problematic. > > - - - > > Thanks in advance to addressing one or more of these issues! > > - Ryan -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
