In my xna game, I have a method to create the treasure chests in random locations on the map. The thing is, it draws them all in the same place. The random doesn’t generate unique random numbers for the v3 points. However, if I debug and step through the method, it works perfectly.
void CreateTreasure()
{
for (int i = 0; i < 20; i++)
{
Random random = new Random();
Treasure t = new Treasure(new Vector3((float)random.Next(0, 600), 0, (float)random.Next(600)));
treasureList.Add(t);
}
}
and in the draw I loop through
foreach (Treasure t in treasureList)
{
DrawModel(treasure, Matrix.Identity * Matrix.CreateScale(0.02f) * Matrix.CreateTranslation(t.Position));
PositionOnMap(ref t.Position);
}
PositionOnMap just takes the position and adjusts the Y to make models sit on the heightmap. Any thoughts?
create the random outside your loop and only use next inside, also use random seed for the initializer like: