*
The moose likes Java in General and the fly likes UUID generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "UUID generation" Watch "UUID generation" New topic
Author

UUID generation

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

Did anyone perform any UUID generation before. Can you please share some knowledge on it. I googled for UUID and I was not able to get sufficient information on it.


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
Javadoc has some information on how a UUID can be created in Java plus a link to some more general information.


Joanne
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

I had a look at javadoc and also had a look at the wikipedia. What I want to know is that would it be good to write a UUID generator algorythm or to just use a Random UUID generator? Any suggestions guys?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Here is what the wikipedia has got to say for random UUID generations,

http://en.wikipedia.org/wiki/UUID#Version_4_.28random.29

Is it worthy to just use a random UUID generation or write a custom one? Please advice!
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

The link below also says that only version 3 and version 4 generation methods are supported in java. So will using a random UUID generator suffice?

http://en.wikipedia.org/wiki/UUID#Java
Charles Lyons
Author
Ranch Hand

Joined: Mar 27, 2003
Posts: 836
So will using a random UUID generator suffice?
How can we possibly say, without knowing what it is that it needs to do?! Will it suffice for what exactly??


Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / Amazon Amazon UK )
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

I simply want to ensure uniqueness for some data.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3429
    
  12
Well, the links you gave show a number of ways of generating UUIDs in Java. Do they meet your needs ? If so, problem solved. If not, then you need to tell us why they don't meet your needs and then maybe we can suggest something else.
Tanu Gulati
Ranch Hand

Joined: Oct 06, 2008
Posts: 113

while generating Guid follow some common process.
1.) it should be a Big String at least 32 bytes
2.) while generating Guid you should not depend on just one resource. you should generate Guid by combing string from atleast 3-4 resources.

For ex. first 12 characters from one resource then some 8 from another one and so on. otherwise there are big changes of mixing up.

for ex. first 11 character you can generate from "System" class using 11 characters from out put of System.getmillSeconds()
then rest 8 you can generate using random number generator and so on.

and one more thing if it a combination of Integer and character it is considered as good one.


thanks
Tanu Gulati
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: UUID generation
 
Similar Threads
finally decided to generate keys this way
canonical string representation
Generating unique Hash in Java
recNo choice
using java.util.UUID