From 140b9e91b30771c62d7cb66aa5bfa3b3b485f224 Mon Sep 17 00:00:00 2001 From: Mateusz Warowny Date: Tue, 15 Feb 2022 18:37:53 +0100 Subject: [PATCH] JAL-3878 Add universal id generator to MathUtils. --- src/jalview/util/MathUtils.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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; + } } -- 1.7.10.2