Is continuously seeding a random number generator performance intensive?

Frustrated c1514843 at drdrb.com
Wed Jan 15 13:23:02 PST 2014


On Wednesday, 15 January 2014 at 21:00:57 UTC, Jeroen Bollen 
wrote:
> How do you correctly create a MersenneTwisterEngine with a 
> ulong as seed?

If you are trying to create a very large 2D noise generator, this 
is how you do it, and you can any degree of smoothness you want:

Create a 2D RNG.

e.g.,

RND2D(x,y) { seed(S + x + N*y); return rand; }


You could use this to generate your whole map very predictably up 
to the seed length(at some point it will repeat because of the 
finite size of the seed).

If you have any degree of smoothness you do not want to use this 
per point unless you do want to have some "noise" which could be 
controlled by weighting the RND2D function so intergrid points 
are not so random:


RND2D(x,y, xS, yS)
{
     s = RND2D(x,y)
     sm1m1 = RND2D((int)(x/xS) - 1, (int)(y / yS - 1));
     sm1m1 = RND2D((int)(x/xS) - 1, (int)(y / yS + 1));
     ...
     return interpolate(s, x, y, sm1m1, sm1p1, ...);
}

where interpolate returns the modified seed that is partially 
based on the seed at the point x,y and partially an interpolation 
value between the sub grid points.

Anyways, now that you have your RND2D you don't ever have to 
pre-generate your noise. Obviously it is more computationally 
expensive though.

I guess this was the function you were looking for before if I 
now understand what you are trying to do?









More information about the Digitalmars-d-learn mailing list