Java SecureRandom ? Java ????????????????,?? java.util.Random ???,??????????????????SecureRandom ??????????????,???????????(IV)??
?????? Java ??? SecureRandom ???:
- ??????:
import java.security.SecureRandom;
- ???? SecureRandom ??:
SecureRandom secureRandom = new SecureRandom();
- ?? SecureRandom ??????:
int randomInt = secureRandom.nextInt(); System.out.println("Random integer: " + randomInt);
- ?? SecureRandom ????????????:
int min = 1; int max = 100; int randomIntInRange = secureRandom.nextInt(max - min + 1) + min; System.out.println("Random integer between " + min + " and " + max + ": " + randomIntInRange);
- ?? SecureRandom ?????????????:
int length = 16; byte[] randomBytes = new byte[length]; secureRandom.nextBytes(randomBytes); System.out.println("Random bytes: " + Arrays.toString(randomBytes));
- ?? SecureRandom ????????????????:
int length = 32; StringBuilder randomHexString = new StringBuilder(); for (int i = 0; i < length; i++) { randomHexString.append(String.format("x", secureRandom.nextInt(256))); } System.out.println("Random hex string: " + randomHexString.toString());
?????????? Java ??? SecureRandom ??????????????,SecureRandom ??????? java.util.Random,????????????????????????????,?????? java.util.Random?