With reference to this programming game I am currently building.
When the game is started, I am generating these robots at supposingly random points on a Canvas, and at first look (adding one or two bots at the same time), this seemed to be working as it should.
...but, when I added a ton of bots at the same time, this is how they where "randomly" appeared on the canvas:
alt text http://img22.imageshack.us/img22/6895/randombotpositionlf7.jpg
The supposedly random points don't seem that random after all...they're just points of a straight line!
Here is how I am calculating the Points:
SetStartingPoint(GetRandomPoint(ArenaWidth, ArenaHeight)); //the width and height are 550, 480 at the moment
//which calls:
private Point GetRandomPoint(double maxWidth, double maxHeight)
{
return new Point(new Random().Next(0, (int)(maxWidth-80)), new Random().Next(0, (int)maxHeight));
}
//and ultimately:
private void SetStartingPoint(Point p)
{
Translate_Body.X = (double)p.X;
Translate_Body.Y = (double)p.Y;
}
As regards the above code, Translate_Body
is of type TranslateTransform
of the robot (canvas
), so by assigning its X
and Y
properties, it will change its position to the new values
What am I missing here?
[UPDATE] Solution:
The problem was like you all suggested, the numbers weren't being seeded properly because of the new instantiations.
I now changed the code to use a single Random
variable and to seed all the points from it.
But I still can't understand why the points where being generated at a seemingly straight line of coordinates. Is anyone able to explain this ?