I am working on an algorithm for generating smooth terrain in C # and am using XNA to display data.
I do this so that it creates a new point halfway between each point to iterate at a random height between them. This works fine, and I set it so that in the second iteration it selects a random point, like in slide two, instead of trying to create a new point between points located on the same axis.
What happens is that the loop uses the same random value from the previous iteration: http://i.stack.imgur.com/UmWr7.png
This is not ideal, obviously, since it is not the correct random generation.
If I use Thread.Sleep(20) after each point generation, it works correctly: http://i.stack.imgur.com/KziOg.png
I do not want to use the Sleep workaround, if possible, as it is very slow, and I would like to use it in real time. I'm pretty sure this has something to do with the C # garbage collector.
Here is my recipient point code
Random r = new Random(); int x = (p1.X + p2.X) / 2; int y; if (!initial) y = r.Next(Math.Min(p1.Y, p2.Y), Math.Max(p1.Y, p2.Y)); else y = r.Next(Math.Min(p1.Y, p2.Y) - Game1.screenHeight / 2, Math.Max(p1.Y, p2.Y) + Game1.screenHeight / 2); return new Point(x, y);
Is garbage collection part of the problem?
Any suggestions or solutions to resolve this issue.