fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. long START_EPOCH = -12219292800000L;
  13. long nanosSince = (System.currentTimeMillis() - START_EPOCH) * 10000;
  14.  
  15. long msb = 0L;
  16. msb |= (0x00000000ffffffffL & nanosSince) << 32;
  17. msb |= (0x0000ffff00000000L & nanosSince) >>> 16;
  18. msb |= (0xffff000000000000L & nanosSince) >>> 48;
  19. msb |= 0x0000000000001000L;
  20.  
  21. byte[] uuidBytes = new byte[16];
  22.  
  23. System.out.printf("%x\n", msb);
  24.  
  25. for (int i = 0; i < 8; i++)
  26. {
  27. uuidBytes[i] = (byte) (msb >>> 8 * (7 - i));
  28. //System.out.printf("%x\n", uuidBytes[i]);
  29. }
  30. for (int i = 8; i < 16; i++)
  31. {
  32. uuidBytes[i] = (byte) (msb >>> 8 * (7 - i));
  33. //System.out.printf("%x\n", uuidBytes[i]);
  34. }
  35. long clock = new Random(System.currentTimeMillis()).nextLong();
  36. System.out.printf("%d\n", clock);
  37. // your code goes here
  38. }
  39. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
1fc4e9302f3811e4
4214499448420155079