[GRASS-dev] Using the new s flag or seed option for r.mapcalc in a python script

Paulo van Breugel p.vanbreugel at gmail.com
Thu Jul 24 01:52:38 PDT 2014

How do I use this new flag / seed parameter for r.mapcalc in python 
scripts? I have for example a script where I can define the seed, or if 
left empty I want to set the 's' flag:

     if seed == "":
         grass.mapcalc("$tmp_map = rand(${minval},${maxval})",
             minval = minval,
             maxval = maxval,
             tmp_map = tmp_map)
         grass.mapcalc("$tmp_map = rand(${minval},${maxval})",
             minval = minval,
             maxval = maxval,
             tmp_map = tmp_map)

Where I need to set the flag='s' in the first instance or the seed= in 
the second instance

On 23-07-14 02:14, Glynn Clements wrote:
> 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).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20140724/e7608d6d/attachment.html>

More information about the grass-dev mailing list