[GRASS-dev] r.random still broken on Mac

Glynn Clements glynn at gclements.plus.com
Fri Sep 29 13:46:22 EDT 2006


William Kyngesburye wrote:

> I just did a quick test - removed __APPLE__ from r.random, so it uses  
> the extern lrand48.  I now get a random distribution.

So it's the fake lrand48() that's causing problems?

Doh.

#define lrand48() ((long)((double) rand() * (1<<31) / RAND_MAX))

This produces the correct range, but if RAND_MAX is too small, the
bottom bits will all be zero. The result is actually used as:

            if (make_rand() % nc < nt)

so it's the bottom bits which are the most relevant.

Can you try this instead:

#define lrand48() (((long) rand() ^ ((long) rand() << 16)) & 0x7FFFFFFF)

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list