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

Glynn Clements glynn at gclements.plus.com
Mon Oct 2 14:37:26 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.
> >
> ...
> 
> > Can you try this instead:
> >
> > #define lrand48() (((long) rand() ^ ((long) rand() << 16)) & 0x7FFFFFFF)
> >
> That works.

OK, I'll use that as the fallback.

> So, was there some other reason to use the fake lrand48() on OS X,  
> since the real one seems to work?

Presumably it wasn't always available. It was originally only used for
Cygwin, but OSX was added in:

	revision 1.2
	date: 2000/12/11 13:35:14;  author: markus;  state: Exp;  lines: +1 -1
	added MacOS X/drand sensivity

This was then followed by changes to the name of the macro:

	revision 1.3
	date: 2000/12/12 09:02:19;  author: markus;  state: Exp;  lines: +1 -1
	changed __MAC_OS_X__ to __MAC_OS (next try)

	revision 1.4
	date: 2001/01/26 12:45:43;  author: markus;  state: Exp;  lines: +1 -1
	changed defined(__MAC_OS_X__) to defined(__APPLE__)

Also, note that lrand48() isn't available if you use -ansi unless you
specifically enable it with e.g. -D_SVID_SOURCE or -D_XOPEN_SOURCE. 
This is part of the reason why platform tests should be avoided.

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




More information about the grass-dev mailing list