Håkan Axheim wrote:How can I do that?
There are several ways of generating unique IDs; just one of which is Java's own
UID class, which is guaranteed to be unique
by host.
There are also many ways of generating "probable" unique IDs. For example, an ID containing 3 ints:
(int) (System.currentTimeMillis() / 1000L)
+ (int) (System.nanoTime() % 1000000000L)
+ Random.nextInt()
is pretty likely,
but not guaranteed, to be unique anywhere.
The only problem with IDs like that is that they are very long to print out.
Another possibility for a
character-based ID is to use information about the customer themselves, eg:
surname,substring(0, 4)
+ firstInitial
+ dateOfBirth (as yyyymmdd)
+ Random.nextInt(100000)
which for me would be something like "GUTKW-19570610-44197".
Indeed, Belgian national IDs and UK driving licenses use something similar, but not necessarily in that order.
And finally, there is a sequence number:
If generated correctly, that
can guarantee uniqueness, and is also generally quite small; but the "correctly" part usually involves a database.
HIH
Winston