code_junkie

How can I assemble bits into a long to create a unique ID?

Nov 12th, 2011
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. long getUniqueID()
  2. {
  3. long timestamp = System.currentTimeMillis();
  4. long random = some random long
  5.  
  6. ...
  7.  
  8. return id;
  9. }
  10.  
  11. return java.util.UUID.randomUUID().getLeastSignificantBits();
  12.  
  13. public class UniqueID {
  14. static long current= System.currentTimeMillis();
  15. static public synchronized long get(){
  16. return current++;
  17. }
  18. }
Add Comment
Please, Sign In to add comment