public static String getRandomHexString(int length){
        byte[] bytes = new byte[length/2];
        new Random().nextBytes(bytes);
        return DatatypeConverter.printHexBinary(bytes);
    }
public static String getRandomHexString ( int length ) { byte [ ] bytes = new byte [ length / 2 ] ; new Random ( ) . nextBytes ( bytes ) ; return DatatypeConverter . printHexBinary ( bytes ) ; }
Get a random hexadecimal string of a specified length.
@param length length of the string to produce
@return a random string consisting only of hexadecimal characters