From: Mateusz Warowny Date: Tue, 15 Feb 2022 17:37:53 +0000 (+0100) Subject: JAL-3878 Add universal id generator to MathUtils. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=140b9e91b30771c62d7cb66aa5bfa3b3b485f224;p=jalview.git JAL-3878 Add universal id generator to MathUtils. --- diff --git a/src/jalview/util/MathUtils.java b/src/jalview/util/MathUtils.java index ecbb6e1..ae0885e 100644 --- a/src/jalview/util/MathUtils.java +++ b/src/jalview/util/MathUtils.java @@ -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; + } }