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