My Solution is here
The major problem with this technique is concurrency .
2 or more users with fast machines and network connections ( or many queued docuemnts) can cause this to deadlock.
Easy to do , easy to deply and staple the feature to the site if you want and makes your life easy , as it is an event handler for on the onCreate or onNew.
I have been in this situation a few times, and here is the final working solution.
Why reinvent the wheel when SharePoint already has a Sequence generator that is Thread safe it is called (SharePoint List )
Simply on every Item you need a a new ID , create an Item in the new List , get the ID and give it to your Document List , announcent , or whatever Items you want Unique ID for.
Code is simple but not public.
Thanks and good luck