Is continuously seeding a random number generator performance intensive?
Frustrated
c1514843 at drdrb.com
Wed Jan 15 13:26:57 PST 2014
On Friday, 3 January 2014 at 13:39:41 UTC, Andrea Fontana wrote:
> On Friday, 3 January 2014 at 01:01:21 UTC, Frustrated wrote:
>> On Thursday, 2 January 2014 at 20:38:10 UTC, Jeroen Bollen
>> wrote:
>> [...]
>> e.g.,
>>
>> seed(k);
>> for(i = 1..10)
>> print(rnd(i));
>>
>> and
>>
>> for(i = 1..10)
>> {
>> seed(time);
>> print(rnd(i));
>> }
>>
>> will both produce random sequences of numbers(and random
>> sequences of numbers are "identically random".
>> [...]
>
> The second example is error-prone. If "time" var doesn't change
> between cycle, it's not random at all.
Wrong, in this example I'm using rnd(i) as having a seed i.
Obviously, I'm not using i as an interval.
i still changes per iteration of the loop so rnd still changes.
(if I did not seed the rnd I would not have used rnd(i) but rnd;)
i.e.,
for(i = 1..10)
{
seed(time);
print(rnd(i));
}
and
for(i = 1..10)
{
seed(time);
print(rnd);
}
are different
but my example could easily have been written as
for(i = 1..10)
{
seed(time+i);
print(rnd);
}
which may be more obvious. The point of writing it the first way
was to try to make it more clear about actually changing the seed
vs the ith random number. (the seed changes the sequence of
random numbers to another sequence but rnd returns the ith value
in the sequence which is ultimately cyclical)
More information about the Digitalmars-d-learn
mailing list