Java\'s UUID class generates a random UUID. But this consists of letters and numbers. For some applications we need only numbers. Is there a way to generate random UUID that
Although the original poster of this question marked @Jigar Joshi's question as the best answer, I'd like to add that there is a rationale to use UUIDs rather than random numbers in certain cases. The difference is that UUIDs are (universally) unique (hence the name) while random numbers are not. It's just a question of probability whether you get the same number twice or even more often when generating random numbers, but this will never happen with UUIDs. Therefore, I'd consider @Chris Eibl's answer as the best one.
Call hashCode()
on the UUID to get a unique integer.
Why using the UUID class if you dont need an UUID? It sounds more like you need just a random number which can be achieved by using the java.util.Random
class.
String uuid = UUID.randomUUID().toString().replaceAll("-", ""); //strips '-'