随机数
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
package com.flagnote.note.utils;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
public class RandomUtils {
|
||||
|
||||
public static SecureRandom sr = null;
|
||||
|
||||
public static ThreadLocalRandom getRandom() {
|
||||
return ThreadLocalRandom.current();
|
||||
static {
|
||||
try {
|
||||
sr = SecureRandom.getInstanceStrong();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
sr = new SecureRandom();
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer nextInt(Integer num) {
|
||||
return getRandom().nextInt(num);
|
||||
return sr.nextInt(num);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user