This question already has an answer here:
I've basically generated a random bytes by calling random.nextBytes(bytes) function but whenever I am re-running this code, it's returning the same bytes, I want to have different bytes everytime I re-run the program.
Thanks in advance
import java.util.*;
import java.math.*;
import java.security.SecureRandom;
public class RandomDemo {
public static void main( String args[] ){
// create random object
SecureRandom randomno = new SecureRandom();
// create byte array
//byte[] nbyte = new byte[30];
// put the next byte in the array
byte[] bytes = new byte[20];
randomno.nextBytes(bytes);
// check the value of array
System.out.println("Value of byte array: " + bytes);
}
}
Aucun commentaire:
Enregistrer un commentaire