[GRASS-dev] r.mapcalc addition
joel.pitt at gmail.com
Mon Oct 23 22:26:04 EDT 2006
On 10/24/06, Hamish <hamish_nospam at yahoo.com> wrote:
> Glynn Clements wrote:
> > > what if r.mapcalc's rand(a,b) fn had an optional third argument? ie
> > > the seed. rand(a,b) would work as it currently does, but
> > > rand(a,b,seed) would be available if you wanted it.
> > That could be problematic if you have more than one call to rand(). We
> > don't actually specify the evaluation order (GRASS functions don't
> > have side effects).
> > If r.mapcalc used G_parser(), a seed=... option would be the obvious
> > choice, but it doesn't, and that can't easily be changed. An
> > environment variable is probably the next best thing. For scripts,
> > setting an environment variable is typically easier than substituting
> > into an r.mapcalc expression (particularly if you are reading the
> > expression from a file).
> if you have more than one call to rand() and both are seeded with the
> same value (GRASS_RND_SEED or whatever), won't you get the same "random"
> number both times?
> should the seed be read on startup in main.c, not xrand.c ..?
I implemented a static variable in rand function, so that it will only
be read the first time rand() is called - independent of how many
rand() occurences are in the expression.
However, I'll follow Glynn's suggestion and read the seed in the
evaluate() function. This will be more robust if other functions are
implemented that call the RNG.
On this topic, would there be any call for implementing more
complicated probability distribution functions? Or is the philosophy
of mapcalc to have the simplest elements necessary?
"Wish not to seem, but to be, the best."
More information about the grass-dev