请帮帮我,我想用1到10来生成随机数 SecureRandom,我该怎么做?
答案 0 :(得分:5)
您可以通过此操作执行操作:
Random rand = new SecureRandom()
// 1 to 10 inclusive.
int number = rand.nextInt(10);
答案 1 :(得分:0)
试试这个解决方案吧。
public static void main (String args[]) {
try {
SecureRandom number = SecureRandom.getInstance("SHA1PRNG");
// Generate 10 integers 1..20
for (int i = 1; i <= 10; i++) {
System.out.println(number.nextInt(10));
}
} catch (NoSuchAlgorithmException nsae) {
// Forward to handler
}
}