Java tutorial
//package com.java2s; import java.security.SecureRandom; public class Main { public static String randomBytesAsHexString(int byteCount) { SecureRandom rng = new SecureRandom(); byte[] randomData = new byte[byteCount]; rng.nextBytes(randomData); StringBuilder builder = new StringBuilder(); for (byte byteValue : randomData) { builder.append(String.format("%02x", byteValue)); } return builder.toString(); } }