JAL-3878 Initial preparation.
[jalview.git] / src / jalview / util / MathUtils.java
index ecbb6e1..819d17f 100644 (file)
@@ -39,4 +39,17 @@ public class MathUtils
     return gcd(b, a % b);
   }
 
+  
+  private static int uidCounter = (int)(Math.random() * 0xffffffff);
+  /**
+   * Generates a unique 64-bit identifier.
+   */
+  public static long getUID()
+  {
+    long uid = 0L;
+    uid |= ((System.currentTimeMillis() >> 10) & 0xfffffffL) << 36;
+    uid |= (long)(Math.random() * 0xfL) << 32;
+    uid |= ++uidCounter & 0xffffffff;
+    return uid;
+  }
 }