POV-Ray : Newsgroups : povray.general : QUESTION: Random Seed deriving from Time? : Re: QUESTION: Random Seed deriving from Time? Server Time
23 Apr 2024 03:04:32 EDT (-0400)
  Re: QUESTION: Random Seed deriving from Time?  
From: clipka
Date: 18 Feb 2018 21:22:31
Message: <5a8a34e7$1@news.povray.org>
Am 18.02.2018 um 22:24 schrieb Sven Littkowski:
> I am trying this
> #declare MyRandomer   = seed(CURRENTTIMESTAMP);
> 
> and this
> #declare MyRandomer   = seed(msg:CURRENTTIMESTAMP);
> 
> but only errors. please assist. Thanks!

Out of pure curiosity: How did you come up with that particular syntax?


The keyword you're looking for is `now`, which returns the time elapsed
since 2000-01-01, 00:00:00 GMT, in (fractional) days.

Note that since `seed()` converts its parameter to an integer, you need
to scale the result of `now` to whatever granularity you need for the
seed. For instance, for the seed to change every hour, use:

    #declare MyRandomer = seed(now * 24);

Note that the value of `now` changes even during parsing.

Also note that the resolution of the underlying timer may vary between
systems, and may be as poor as a second per tick.


Finally, due to the nature of the inbuilt random number generator, the
first few values pulled from the generator may remain somewhat similar
between consecutive seeds, so you may want to choose your granularity
somewhat higher than absolutely necessary, or always discard the first
few random numbers (maybe a dozen or so) pulled from the generator.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.