X-Received: by 10.66.84.136 with SMTP id z8mr1780771pay.2.1358712004611; Sun, 20 Jan 2013 12:00:04 -0800 (PST) X-Received: by 10.50.108.137 with SMTP id hk9mr2263942igb.15.1358712004573; Sun, 20 Jan 2013 12:00:04 -0800 (PST) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!f6no2312646pbd.1!news-out.google.com!6ni7788pbd.1!nntp.google.com!ld4no2289898pbb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Sun, 20 Jan 2013 12:00:04 -0800 (PST) In-Reply-To: <2sbnf8lu7vidolv11m33tcsmuh4olkt21h@4ax.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T NNTP-Posting-Host: 173.164.137.214 References: <50e8eb1f$0$284$14726298@news.sunsite.dk> <2sbnf8lu7vidolv11m33tcsmuh4olkt21h@4ax.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4735bb8e-f2d8-4de9-9d5f-cd62d4c77dff@googlegroups.com> Subject: Re: single instance From: Lew Injection-Date: Sun, 20 Jan 2013 20:00:04 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.java.programmer:21590 Roedy Green wrote: > Knute Johnson wrote, quoted or indirectly quoted someone who said : >> Below is what I ended up with. I'm curious about the UUID. How do you= =20 >> create a time based UUID? And does it have less granularity that=20 >> currentTimeMillis? >=20 > there are specified formulas for creating UUIDs. I think one way of > rapidly generating them would be to use System.currentTimeMillis for > the high 64 bits and System.nanotime for the lower 64 bits, but I > suspect that would not be considered kosher. >=20 > Another would be to use SecureRandom to generate 16 bytes, though that > probably is not as unique as you might hope. >=20 > a UUID is not just 128 bits. It has embedded fields that tell you how > it was generated. http://docs.oracle.com/javase/7/docs/api/java/util/UUID.html =ABThe layout of a variant 2 (Leach-Salz) UUID is as follows: The most sign= ificant long consists of the following unsigned fields: 0xFFFFFFFF00000000 time_low 0x00000000FFFF0000 time_mid 0x000000000000F000 version 0x0000000000000FFF time_hi ... =ABFor more information including algorithms used to create UUIDs, see RFC = 4122: A Universally Unique IDentifier (UUID) URN Namespace,=20 http://www.ietf.org/rfc/rfc4122.txt section 4.2 "Algorithms for Creating a Time-Based UUID".=BB --=20 Lew