这是我带注释的代码。
class RandomThing{
// This is one way to do it, but I want more randomness.
protected final static Random rand = new Random();
// This is how I do it with SecureRandom.
protected final static Random rand = new SecureRandom();
// Here is the best way I can get a strong instance, but rand is no longer final.
protected static Random rand = null;
static {
try {
rand = SecureRandom.getInstanceStrong();
} catch (NoSuchAlgorithmException ex) {
// Blow up.
}
}
}
我怎么能有这样的东西?
protected final static Random rand = SecureRandom.getInstanceStrong();
// not okay because getInstanceStrong throws NoSuchAlgorithmException