Philipp Kraus <>, on 22/08/2010 15:48:49, wrote:
> Hi,
>
> I'm implementating some algorithems with random data, so I must
> initialisation the seed. But the code creates many objects of my class
> so that the seed, which is set to
> static_cast<std::time_t>(time(0)))
> is in all objects the same and so I get in all objects the same "random
> values".
>
> My idea for solving this seed problem, ist to mix the time with the
> object reference (*this).
> Is this a good solution or do you know another algorithm? How can I
> convert the reference to a numeric value?
As an aside from all the other replies, since it could be a good thing
to have different seeds in order to have different and reproducible
random sequences, you could, first of all, get a PRNG that you can
instantiate separately.
Once you have the first instance, set its seed from time(), and then
generate the further seeds from that first instance, seeds to be passed
to the further instances of the PRNG contained in your classes.
Doing things in this way you'll have a single originating seed for each
run of your program, a seed that you could eventually reuse to debug the
program or to simply reproduce past runs.
--
FSC -
http://userscripts.org/scripts/show/59948
http://fscode.altervista.org -
http://sardinias.com