Code example for Random

 * @date 2011-8-24 
public class XIDGenerator { 
    public static final String UNIQUE_QUALIFIER = "UniqueQualifier";
    private final static Random rand = new Random();
    private static byte[] randomBytes() { 
        final byte[] bytes = new byte[rand.nextInt(10)];
        return bytes;
    public static XATransactionId createXID(final int formatId) {
        final byte[] branchQualifier = randomBytes();
        final byte[] globalTransactionId = randomBytes();
        final XATransactionId xid =
                new XATransactionId(formatId, branchQualifier, globalTransactionId, UNIQUE_QUALIFIER);
Connect your IDE to all the code out there  Get Codota for Java