aftab
aftab

Reputation: 1141

Unique ID Code in Java

Hi I want you guys suggestion.

I want to create a 15 length key code form current time stamp. Code should contain small and capital characters with digits. Anyone can suggest how I can create a 15 length unique code from current time stamp? Using Java in servlet side.

Upvotes: 0

Views: 183

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074028

Given your constraints, I'd probably create a GUID, append or prepend a timestamp, and transform it into the 15-letters format. GUIDs are 32 hexadecimal digits and so have 32^16 (1.20892582x1024) possible values (although not all of them are used). 15 characters with digits or upper or lower case English letters (so, 62 possible values per digit) gives you 15^62 (8.272905461x1072) — plenty of room. If you were okay adding + and / to your list of possible characters, you could use Base64 encoding rather than doing it yourself.

Upvotes: 1

Related Questions