// Generating random hex String up to 16 characters long private static Random wheel = new Random(); // seed with time of day // ... /* Note there is no such method as Random.nextLong( long ), * so you have to trim the result to 0..Long.MAX_VALUE yourself. */ /* To get numeric strings with digits 0-9 try this: */ String almostUniqueAndRandom = Long.toString( wheel.nextLong() & Long.MAX_VALUE ); /* generate random hex Strings of form * "0" .. "7fffffffffffffff", a maximum 16 characters long. * representing 0..Long.MAX_VALUE * To get strings with letters a-f and digits 0-9 try this: */ String almostUniqueAndRandom = Long.toHexString( wheel.nextLong() & Long.MAX_VALUE ); /* To get strings with letters a-z and digits 0-9 try this: */ String almostUniqueAndRandom = Long.toString( wheel.nextLong() & Long.MAX_VALUE , 36 );