Hi Paul,

I've used Sean Luke's implementation quite a few times before:

http://cs.gmu.edu/~sean/research/mersenne/MersenneTwister.java

It is pretty good, fast and battle tested (it is used extensively in
ECJ - an genetic algorithm and genetic programming java package,
another project of his).

Concerning generating random numbers in different threads, there is a
simple Mersenne Twister extension you can use to ensure that all
random generators are independent (or as independent as pseudorandom
generators can be). It is detailed in this paper here, by the author
of Mersenne Twister himself:

http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/DC/dgene.pdf

The only thing you will need is some sort of numerical unique ID for
each thread - it can be sequencial or even generated randomly using
Java UUIDs or the like.

Hope this helps,

Artur


On May 27, 11:24 pm, Paul Moore <p.f.mo...@gmail.com> wrote:
> I want to write a reasonably high-performance simulation program in
> Clojure. For the random numbers, I'd prefer to use Mersenne Twister
> (for a number of reasons - it's a well-known, good RNG, and it's
> commonly used in a number of other languages I use, so it's a good
> baseline for comparing implementations). The Java RNG, which Clojure
> uses, is not MT, but Knuth's linear congruential RNG.
>
> 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?
>
> 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?
>
> Thanks,
> Paul.

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

Reply via email to