So I declare a random generator in one of my classes like this
static Random random = new Random(DateTime.Now.Millisecond);
and when calling a function in the class even when that function was blank it appeared to block the entire program from running.
static Random random = new Random();
But when I do this it worked as expected?
EDIT with code:
This program is specifically an XNA Game so here is the update function
protected override void Update(GameTime gameTime)
{
Debug.WriteLine("This happenens");
EnemyController.generateEnemies();
Debug.WriteLine("This does not");
}
And here is part of the other class
public static class EnemyController
{
static Random random = new Random(DateTime.Now.Millisecond);
public static void generateEnemies()
{
Debug.writeLine("This code wont run");
}
}
As stated in the MSDN documentation for System.Random for the parameterless constructor:
If your instantiation of Random is actually what’s blocking your code, then know that you don’t need to seed it with the time. However, I would look into other possibilities for your code blocking.