Is continuously seeding a random number generator performance intensive?

Frustrated c1514843 at drdrb.com
Thu Jan 2 17:01:19 PST 2014


On Thursday, 2 January 2014 at 20:38:10 UTC, Jeroen Bollen wrote:
> D provides a set of Random Number Generators in std.random. I 
> am writing an application which would create a 2D map of noise. 
> To do this though, I'll have to calculate the same random 
> numbers over and over again. (I cannot store them, that'd take 
> a horrible amount of RAM. )
>
> Is it good to re-seed a generator for every coordinate, will 
> this be performance intensive? Is there maybe way to easily 
> implement Generator.at(uint x) in D?

I believe you fail to understand how the RNG's work.

You supply a seed(a value) and they generate a deterministic 
sequence off that value that is pseudo-random relative to each 
other..

If you re-seed the generator every time you are not doing 
anything but wasting cycles since the new element will be random, 
but the same as using the next element in the sequence in the 
first case.

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 nice thing about the first case is that you can save the seed 
once time and produce the exact same sequence... which would save 
you memory. In the second case you would have to record every 
seed to recover the sequence.


More information about the Digitalmars-d-learn mailing list