Code example for Random

Methods: nextBytes, nextInt

0
    public static final String UNIQUE_QUALIFIER = "unique-qualifier";
    private final static Random rand = new Random();
 
 
    private static byte[] randomBytes() { 
        final byte[] bytes = new byte[rand.nextInt(100)];
        rand.nextBytes(bytes);
        return bytes;
    } 
 
 
    public static XATransactionId createXID(final int formatId, String uniqueQualifier) {
        final byte[] branchQualifier = randomBytes();
        final byte[] globalTransactionId = randomBytes();
        final XATransactionId xid =
                new XATransactionId(formatId, branchQualifier, globalTransactionId, uniqueQualifier);
        return xid;
    } 
 
 
    public static XATransactionId createXID(final int formatId) {