Generating a random set of bytes

Use the class Random. It contains a function nextBytes to which you pass a byte array of a certain length. After the call, each element of this byte array will contain a random byte value.

Main.java:

import java.util.*;
  
public class Main {   
   public static void main(String[] args) throws Exception {
 
      Random r = new Random();
      byte b[] = new byte[100];
      r.nextBytes(b);
 
      for (int i=0; i<b.length; i++) {
         System.out.print(b[i] + " ");
      }
   }
}

outputs:

96 23 -71 -25 32 116 -32 104 -120 99 -35 25 57 -5 120 -92
34 4 83 112 -77 44 -45 -57 -108 107 -73 71 -89 -116 -29 -51
85 119 -20 -110 -98 104 -44 37 -101 27 92 93 104 -95 9 45 
-4 -128 74 -22 -16 -79 60 -126 52 -101 -24 -96 37 -17 -53 
-69 120 -72 115 24 50 -80 38 87 -17 90 -68 82 -106 19 8 26
81 106 80 78 -33 -68 112 106 -69 -127 117 -119 20 0 -117 
-110 54 94 -7 -73