[GRASS-dev] using rand(x,y) in r.mapcalc (grass7)

Glynn Clements glynn at gclements.plus.com
Tue Jul 22 17:14:00 PDT 2014


Glynn Clements wrote:

> I'm inclined to add both an option (to specify a seed, replacing the
> environment variable) and a flag (to seed from the system clock or
> whatever), and having the PRNG generate a fatal error if neither of
> those are used.

This is now done.

r61350 adds the lrand48/mrand48/drand48 equivalents to lib/gis. Brief
testing suggests that the results are identical to those generated by
GNU libc (which should be identical to any other POSIX implementation).

r61352 changes it to generate a fatal error if used prior to seeding.

r61353 changes r.mapcalc so that seeding is performed via seed= or -s. 
The seed (whether specified by seed= or generated for -s) is added to
the history (for r.mapcalc; r3.mapcalc's create_history() function is
a stub; do 3D rasters have history?)

Note that GRASS_RND_SEED is no longer supported. That was a hack from
the time before r.mapcalc used G_parser().

As I write this, it has occurred to me that the behaviour of rand()
may be non-deterministic in the presence of certain forms of
parallelism, e.g. multiple occurences of rand() in the expression(s)
in conjunction with pthreads. Ultimately we may need to expand the
PRNG to support explicit state (as per erand48, nrand48 and jrand48).

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


More information about the grass-dev mailing list