How to create an array of 20 random bytes? November 18, 2022 by Tarik Try the Random.nextBytes method: byte[] b = new byte[20]; new Random().nextBytes(b);