Hi Paul,

On 27 May 2010 23:24, Paul Moore <[email protected]> wrote:

> Can someone recommend a good Mersenne Twister implementation I could
> use? A web search finds a number of implementations in Java -
> presumably I can use these via Java interop - is that a sensible thing
> to do?

It is very sensible to use an existing java library in this case: i)
the code exitsts so you don't have to write it, ii) it will probably
have a reasonably nice interface to use from clojure, and iii) the
performance will most likely be better.

A quick Google found this page:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/JAVA/java.html

If I'm not mistaken, these are the guys who wrote the original
Mersenne twister paper.

> I'm also looking to parallelise my simulation, so I'd want to have
> multiple threads all generating random numbers. I'm not an expert in
> this field, if I just naively generate random numbers in multiple
> threads is that OK, or could it compromise the randomness? If there is
> an issue, has anyone got a pointer to a thread-safe MT implementation
> that I could use?

First of all, the RNG will maintain internal state, so accessing it
from multiple thread willy-nilly will corrupt that state. It could be
that the implementation that you decide to go with will protect the
internal state with locks in which case you're ok. The other thing to
consider is speed: any kind of locking will slow down the RNG.

So if in your application it's ok to have one RNG instance per thread,
then you can avoid locking, and the speed penalty. On the other hand,
if you want all of the threads to use the same RNG instance for some
reason (e.g. deterministic behaviour) then you'll need to use a single
RNG instance that is shared across your threads. If you do need
deterministic behaviour it might be possible to seed all your RNG
instances the same and that way produce deterministic behaviour across
multiple RNG instances. I guess this depends on the MT implementation.
Also, I'm not sure if this is possible with MT or not.

> Paul.

-- 
  ! Lauri

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

Reply via email to