.NET: will Random.Random operate differently inside a static method
- by Craig Johnston
I am having difficulty with the following code which is inside a static method of a non-static class.
int iRand;
int rand;
rand = new Random((int)DateTime.Now.Ticks);
iRand = rand.Next(50000);
The iRand number, along with some other values, are being inserted into a new row of an Access MDB table via OLEDB. The iRand number is being inserted into a field that is part of the primary key, and the insert attempt is throwing the following exception even though the iRand number is supposed to be random:
System.Data.OleDb.OleDbException: The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.
Could the fact the method is static be making the iRand number stay the same, for some reason?