On Thu, Nov 19, 2009 at 9:17 PM, Mark Triggs <mark.h.tri...@gmail.com>wrote:
> A good example is: > > (take 10 (repeatedly #(rand-int 100))) > > to get a bunch of random integers. I actually quite like this idiom, > even if there's a bit of ascii involved :) > Why not abstract it some, though? (defn rand-seq [range] (repeatedly #(rand-int range)) ; in library code ... (def rand100 (rand-seq 100)) ; in project that will need ; randoms from 1 to 100 from time to time ... (take 10 rand100) ; at a point when ten such are needed Of course, technically these all have side effects, but conceptually successive random numbers are independent, so conceptually all of these are referentially transparent (in that the statistical properties of the random values are invariant rather than the actual values you'll actually see). In practice, and assuming as seems likely that Clojure's "rand" updates the PRNG's internal state atomically when callers are concurrent, the results will be a bit MORE random and independent than usual for a PRNG. -- 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