.NET: will Random.Random operate differently inside a static method
Posted
by Craig Johnston
on Stack Overflow
See other posts from Stack Overflow
or by Craig Johnston
Published on 2010-04-29T07:57:37Z
Indexed on
2010/04/29
8:07 UTC
Read the original article
Hit count: 412
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?
© Stack Overflow or respective owner