-7

I am trying to generate a random unique number for every Http request hitting my application.

How do make sure the uniqueness of such a number. Does java provide any method or API for this?

msam
  • 4,259
  • 3
  • 19
  • 32
Ankit
  • 113
  • 1
  • 7

2 Answers2

4

You could use the java.util.UUID class for that.

UUID rand = UUID.randomUUID();
System.out.println(rand);
Rahul
  • 44,383
  • 11
  • 84
  • 103
2

You could use java.util.Random - http://java.about.com/od/javautil/a/randomnumbers.htm

rvini
  • 441
  • 2
  • 4
  • 12