On Fri, Oct 14, 2011 at 2:33 PM, Zsbán Ambrus <[email protected]> wrote:
> On Fri, Oct 14, 2011 at 1:08 PM, Ewart Shaw <[email protected]> wrote:
>> I want to generate pseudorandom sequences that are the same for 32- & 64-bit 
>> J.
>
> 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.

Hmm, from a quick test, it seems Roger is right: none of the built in
generators give the same results on the 32-bit and 64-bit J.

Let's use the random generation functions from GSL (
http://www.gnu.org/software/gsl/ ) then.  This example implements
roll, but not deal.


$ cat rngwrap.c
#include <gsl/gsl_rng.h>

/*
Allocate a new random generator of the Mersenne Twister algorithm
and initialize it with the default seed.
*/
gsl_rng *
wrap_newrng(void) {
        gsl_rng *g = gsl_rng_alloc(gsl_rng_mt19937);
        return g;
}

$ cat rngwrap.ijs
NB. random generator functions from GSL
rngobj=: <'./rngwrap.so wrap_newrng > x'15!:0$0
rollint=: './rngwrap.so gsl_rng_uniform_int > x *c x'15!:0 rngobj;]
rollflo=: './rngwrap.so gsl_rng_uniform_pos > d *c'15!:0 (,<rngobj)"_
roll=: rollflo`rollint`[:@.*"0 :[:

$ gcc -Wall -O -fpic -lm -lgslcblas -lgsl -shared -o rngwrap.so rngwrap.c
$ jconsole rngwrap.ijs
   roll (10$1e4),5$0
9997 1629 2826 9472 2316 4849 9574 7443 5400 7399 0.759944 0.658637
0.315638 0.804403 0.519672



Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to