[GRASS5] r.random broken

Hamish hamish_nospam at yahoo.com
Sat Jun 4 11:45:26 EDT 2005


> >> I just tried to use r.random to generate a set of random points
> >> across the Spearfish dem file_to illustrate interpolation.
> >> 
> >> When I display the points, they are all clustered along the top
> >> (i.e., north) edge. This happens with both raster and vector
> >> points, and when I run it against both elevation.dem and
> >> elevation.10m. It looks something is wrong with the algorithm to
> >> generate the y values.
> > 
> > r.random totally won't work if either __CYGWIN__ or __APPLE__ are
> > defined, due to the following in raster/r.random/creat_rand.c:
> > 
> > #if defined(__CYGWIN__) || defined(__APPLE__)
> > #define lrand48() rand()/32767.0
> > #define srand48(sv) (srand((unsigned)(sv)))
> > #else
> > 
> > lrand48() is supposed to return random numbers between 0 and 2^31.
> > The above lrand48() macro will end up returning values which are far
> > too small, so, the random test will return true too often, resulting
> > in the desired number of random cells being reached far too early.
..
> Thanks for identifying the cause of the behavior I observed.
> 
> This is weird. Why is this module programmed to work incorrectly on
> Apple and Cygwin systems??? Can it be corrected?


just replace 32767.0 with 2^31. Maybe try-

#define lrand48() rand()/2147483648.;

or
rand()/2.1475e+09;

or
#include <math.h>   // & link with -lm
..
rand()/exp2(31);


?


Hamish




More information about the grass-dev mailing list