The first question is, why do you want to generate an ID in your application? IF you're using SQL Server for example, then you can define the ID column as identity (
http://msdn.microsoft.com/en-us/library/ms186775.aspx[
^]).
Another thing is that if you just generate random numbers it's quite likely that you get the same number at some point so it wouldn't serve as a unique ID.