[GRASSLIST:3508] Re: seeds for r.random

Glynn Clements glynn.clements at virgin.net
Fri Apr 12 05:12:13 EDT 2002


Roy Sanderson wrote:

> I'm using GRASS 4.2.1 and am having problems with r.random giving similar
> random data (its running repeatedly inside a unix script).  Is there a
> possible way of setting seed values (e.g. based on the time or process-id
> no) into r.random?

I don't know about 4.2.1, but in 4.3 the PRNG is initialised with
either:

    srand48( (long) time( (time_t *) 0) );
or:
    srand(getpid());

depending upon whether it was compiled to use lrand48() or rand().

If it uses lrand48() then it will produce the same output if run twice
within one second. OTOH, some systems have very poor rand()
implementations, whose output is far from random (e.g. a short cycle
producing too few distinct values, or simple dependencies between
successive values).

Try sleeping between runs, in case it's the time issue. Otherwise, you
would need to modify the source code to use a better PRNG.

-- 
Glynn Clements <glynn.clements at virgin.net>



More information about the grass-user mailing list