[Jprogramming] 32- & 64-bit PRNGs
Zsbán Ambrus
ambrus at math.bme.hu
Fri Oct 14 20:33:34 HKT 2011
On Fri, Oct 14, 2011 at 1:08 PM, Ewart Shaw <ewartshaw at gmail.com> wrote:
> I want to generate pseudorandom sequences that are the same for 32- & 64-bit J.
> I need better statistical properties than the old linear congruential generator
> as in 'roll' & 'deal' at http://www.jsoftware.com/help/release/random.htm .
Have you tried the other random generators the (9!:43) foreign makes
available? I'd guess some of them are the same for 32 and 64 bit J.
If that fails,
> I could implement the 32-bit MT19937 'by hand' in J
I'd recommend against that: instead pull in a C library that
implements that or some other random generator, such as GSL, with the
J foreign interface (15!:). If you have trouble with this, tell me
and I'll try to help.
You may still have to implement deal if you need it. The case when
the right argument isn't too large is implemented in GSL, but the case
when the right argument is very large and its left argument is small
isn't trivial. If you need this latter case, one implementation can
be found in the J source code: this is a very tricky algorithm using a
sparse table; a different algorithm is given in Knuth chapter 3.4.2
exercise 15.
Ambrus
More information about the Programming
mailing list