Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3678130
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:18:16+00:00 2026-05-19T03:18:16+00:00

I usually use the UUID class to generate unique IDs. This works fine if

  • 0

I usually use the UUID class to generate unique IDs. This works fine if these IDs are used by technical systems only, they don’t care how long they are:

System.out.println(UUID.randomUUID().toString());

> 67849f28-c0af-46c7-8421-94f0642e5d4d

Is there a nice way to create user friendly unique IDs (like those from tinyurl) which are a bit shorter than the UUIDs? Usecase: you want to send out IDs via Mail to your customers which in turn visit your site and enter that number into a form, like a voucher ID.

I assume that UUIDs get generated equally through the whole range of the 128 Bit range of the UUID. So would it be sage to use just the lower 64 Bits for instance?

System.out.println(UUID.randomUUID().getLeastSignificantBits());

Any feedback is welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T03:18:16+00:00Added an answer on May 19, 2026 at 3:18 am

    I assume that UUIDs get generated
    equally through the whole range of the
    128 Bit range of the UUID.

    First off, your assumption may be incorrect, depending on the UUID type (1, 2, 3, or 4). From the Java UUID docs:

    There exist different variants of
    these global identifiers. The methods
    of this class are for manipulating the
    Leach-Salz variant, although the
    constructors allow the creation of any
    variant of UUID (described below).

    The layout of a variant 2 (Leach-Salz)
    UUID is as follows: The most
    significant long consists of the
    following unsigned fields:

    0xFFFFFFFF00000000 time_low 
    0x00000000FFFF0000 time_mid 
    0x000000000000F000 version 
    0x0000000000000FFF time_hi  
    

    The least significant long consists of
    the following unsigned fields:

    0xC000000000000000 variant 
    0x3FFF000000000000 clock_seq 
    0x0000FFFFFFFFFFFF node  
    

    The variant field contains a value
    which identifies the layout of the
    UUID. The bit layout described above
    is valid only for a UUID with a
    variant value of 2, which indicates
    the Leach-Salz variant.

    The version field holds a value that
    describes the type of this UUID. There
    are four different basic types of
    UUIDs: time-based, DCE security,
    name-based, and randomly generated
    UUIDs. These types have a version
    value of 1, 2, 3 and 4, respectively.

    The best way to do what you’re doing is to generate a random string with code that looks something like this (source):

    public class RandomString {
    
              public static String randomstring(int lo, int hi){
                      int n = rand(lo, hi);
                      byte b[] = new byte[n];
                      for (int i = 0; i < n; i++)
                              b[i] = (byte)rand('a', 'z');
                      return new String(b, 0);
              }
    
              private static int rand(int lo, int hi){
                          java.util.Random rn = new java.util.Random();
                      int n = hi - lo + 1;
                      int i = rn.nextInt(n);
                      if (i < 0)
                              i = -i;
                      return lo + i;
              }
    
              public static String randomstring(){
                      return randomstring(5, 25);
              }
    
            /**
             * @param args
             */
            public static void main(String[] args) {
                    System.out.println(randomstring());
    
            }
    
    }
    

    If you’re incredibly worried about collisions or something, I suggest you base64 encode your UUID which should cut down on its size.

    Moral of the story: don’t rely on individual parts of UUIDs as they are holistically designed. If you do need to rely on individual parts of a UUID, make sure you familiarize yourself with the particular UUID type and implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I usually use expressions like this CommandArgument='<%# Container.DataItemIndex.ToString() %> ' But I could not
I usually use perl -de 42 for obtaining an interactive Perl shell. I have
I usually use STATIC implementation when developing Desktop Application and I just got my
I usually use simple quotes, but sometime I get very long lines which I
I usually use something like my $dir=/path/to/dir; opendir(DIR, $dir) or die can't open $dir:
When working with 3d graphics, sample shaders USUALLY use the following operation for vector
I like to use hlsearch but I hate to keep everything highlighted after searching,
I have a recurrent design issue when I use sliders in my photo galleries.
I'm having troubles with a synchronous AJAX call in a JIL widget. Only the
I'm searching a supported way to render a section of code in JSF, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.