cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Ellis <jbel...@gmail.com>
Subject Re: UUIDs whose alphanumeric order is the same as their chronological order
Date Tue, 22 Jun 2010 14:18:24 GMT
Why not just use version 1 UUIDs and TimeUUIDType?

On Tue, Jun 22, 2010 at 8:58 AM, David Boxenhorn <david@lookin2.com> wrote:
> I want to use UUIDs whose alphanumeric order is the same as their
> chronological order. So I'm generating Version 4 UUIDs (
> http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Version_4_.28random.29
> ) as follows:
>
> public class Id
> {
>    static Random random = new Random();
>
>    public static String next()
>    {
>       // Format: xxxxxxxx-xxxx-4xxx-8xxx-xxxxxxxxxxxx
>
>       long high = (System.currentTimeMillis() << 16) | 0x4000 |
> random.nextInt(4096);
>       long low = (random.nextLong() >>> 4) | 0x8000000000000000L;
>
>       UUID uuid = new UUID(high, low);
>
>       return uuid.toString();
>    }
> }
>
> Is there anything wrong with this idea?
>



-- 
Jonathan Ellis
Project Chair, Apache Cassandra
co-founder of Riptano, the source for professional Cassandra support
http://riptano.com

Mime
View raw message