How Can I Generate Random Unqiue Numbers in C#

Posted by peace on Stack Overflow See other posts from Stack Overflow or by peace
Published on 2010-06-17T19:20:15Z Indexed on 2010/06/17 19:23 UTC
Read the original article Hit count: 285

Filed under:
|
|
|
public int GenPurchaseOrderNum()
{
    Random random = new Random();
    _uniqueNum = random.Next(13287, 21439);
    return UniqueNum;
}

I removed unique constraint from the PONumber column in the db because an employee should only generate P.O. # when the deal is set. Otherwise, P.O. # would have 0.

P.O. Number used to have unique constraint, this forces employee to generate P.O. in all cases so the db doesn't throw unique constraint error.

Since i removed the unique constraint, any quote doesn't have P.O. will carry 0 value. Otherwise, a unique value is generated for P.O. #. However, i don't have a unique constraint in db which makes it hard for me to know whether the application generated P.O. # is unique or not.

What should i do?

I hope my question is clear enough

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET