On Wednesday, June 4, 2014 2:55:20 AM UTC-5, Gunnar Völkel wrote:
>
> Once you notice that you usually need a fast solution. 
>

Yes!
 

> The easiest solution is to just pass around an instance of 
> java.util.Random which you create with the desired seed. Another options is 
> to have a constructor function returning a "rand" function.
>
> (defn prng [seed]
>   (let [rnd (java.util.Random. (long seed))]
>     (fn rand [] (.nextDouble rnd))))
>

Thanks.  This is very helpful.  I have not been thoroughly immersed in the 
Java world for many years, so I have to spend a bit of time studying in 
order to figure out this sort of thing on my own.  (I like Clojure because 
I usually only need to deal with Java when I want to, but there are times 
when it's necessary.)
 

> But having a built-in rebindable (thread-local) "rand" is preferable in 
> the long run.
>

Yes, especially since rolling one's own version means coding up any 
higher-level functions that use randomness, when others who have thought 
more about relevant algorithms have already done that work.  Then again, 
their source code is usually available, so one can copy it.  For my present 
purposes, data.generators or bigml/sampling might do what I need. 

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