Im doing a dxball like game for a school project. I am trying to create spawn points for the objects(blocks) that will move across the screen. But my problem is when i lets say create 2 objects of type Block. They will get the same random spawnlocation and they will keep having the same respawn location at all time. So i guess i am doing to random function wrong
public class blocks
{
public Texture2D texturBlock1;
public Vector2 hastighet = new Vector2(500.0f, 000.0f);
public Vector2 position;
private Random random = new Random();
private int Screen = new int();
public blocks(int MaxWith)
{
this.position.X = MaxWith+10;
this.position.Y = random.Next(300);
Screen = MaxWith;
}
I would love if someone could help me out. I am a real novice when it comes to XNA and c#
The Random class in .NET usually uses System.DateTime as it’s seed, so when you’re creating multiple randoms at the same time you tend to get the same seed and generate the same random #.
Try out this static method which uses a GUID as the seed