[GRASS-dev] using rand(x,y) in r.mapcalc (grass7)
Glynn Clements
glynn at gclements.plus.com
Tue Jul 22 13:39:43 PDT 2014
Paulo van Breugel wrote:
> And it seems to be the default behaviour by python/numpy:
It is, but ...
> >>> import numpy as np
> >>> np.random.random()
> 0.8351426142559701
> >>> np.random.random()
> 0.4813823441998394
> >>> np.random.random()
> 0.7279314267025369
... this example doesn't demonstrate that. Any PRNG returns different
values for successive calls.
The question is whether the PRNG's initial value should autmatically
be seeded from some external source of entropy (e.g. the system
clock), so that the sequence of values differs on different runs.
In turn, that brings up questions about the quality of the entropy
source. The ANSI C time() function typically only has one second
granularity (indeed, POSIX requires this, as time_t is defined as
seconds since the epoch), which is sufficiently course that successive
runs may get the same seed. Other functions aren't portable, and even
where available, the granularity isn't guaranteed.
My main objection to automatic seeding is that people will inevitably
produce non-repeatable results without even realising it.
One possible solution would be to automatically add the seed to the
history of any map generated by r.mapcalc (or possibly only those
which use the rand() function). But that would still only help if the
creator either provides access to the generated maps, or the output
from r.info. Simply providing the commands used and the end result
wouldn't help.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list