I wish to generate random integers using SecureRandom in java.
private SecureRandom myRandom = new SecureRandom();
private int myInt = 10;
int myResults;
myResults = myRandom.nextInt(myInt);
I understand that seeding means specifying a starting point for the random number generator. Shoud I reseed the random number generator after every iteration to ensure randomness?
No. The SecureRandom will seed itself if you don’t provide a seed the first time, and if it’s using a pseudo-random generator, subsequent random numbers will be unpredictable.
In fact, if you try to reseed it, you’ll likely reduce the security of the random numbers generated, since you’ll have to get the new seed from somewhere (and that will likely not be as good a source of randomness as the SecureRandom’s implementation).
According to https://www.synopsys.com/blogs/software-security/proper-use-of-javas-securerandom/, if you are using the SecureRandom for a large number of random numbers, you should periodically reseed it, so either
But don’t reseed it after every call.
Note that
SecureRandom‘s API is due to be clarified in Java 8: http://openjdk.java.net/jeps/123