RANDOM() and RANDOM(FALSE) problem



Stavros Macrakis wrote:
> Having the same generator on every platform would be ideal.

Richard Fateman wrote:
> Only if it is as fast as possible on every platform.

I'm inclined to think that we can have both portability and 
acceptable performance across platforms.

I found a Lisp implementation of the Mersenne twister.
This implementation loads into CMUCL, Clisp, and GCL out 
of the box. As you know, CMUCL's RANDOM is a MT 
implementation also, but it doesn't drop into Clisp or GCL.

In a simple test (a Monte Carlo integration) calling MT-RANDOM
from Maxima random (instead of RANDOM) to fill an array with
random numbers takes about 1.5 times as long (Clisp) or five times
as long (CMUCL). But since that's only part of the work, the
overall time to finish the computation is about 1.2 times as
long (Clisp) or twice as long (CMUCL). 

I didn't try the test with GCL Maxima, as I don't have it installed.
I guess that if we used some MT implementation, we don't
even need to replace CMUCL's rng, just make sure we can
set the state the same as for other Lisps.

Naturally this short test doesn't prove much, but it does
provide some evidence that we needn't worry too much about
sacrificing speed for portability. Something to consider.

For what it's worth,
Robert Dodier

PS. Here's a link to MT-RANDOM: http://www.lisp-p.org/jmt/
(jmt.lisp is the MT implementation)

PPS. Here's my test script. I used makelist instead of a loop
in order to separate the rng time from function evaluation time.
In any event, if rearranged to use a loop, the computation
takes just about the same total time.

f(x) := exp (-((x^2-1)/2));

x1: 1;
integrate (f(x), x, -x1, +x1);
%, numer;

showtime: true$

n: 10000$

x: makelist (random(2.0*x1)-1, i, 1, n)$
fx: map (f, x)$

apply ("+", fx) * 2*x1/n;

load ("jmt.lisp");
:lisp (defmfun $random (x) (mt-random x))

x: makelist (random(2.0*x1)-1, i, 1, n)$
fx: map (f, x)$

apply ("+", fx) * 2*x1/n;



		
__________________________________ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail