随机数

This commit is contained in:
Jesse-Ma
2022-12-26 11:07:06 +08:00
parent dce7172987
commit a82eef1afe
2 changed files with 12 additions and 4 deletions

View File

@@ -1,2 +1,4 @@
# flagnote-service # flagnote-service
flagnote-service flagnote-service
-Djava.security.egd=file:/dev/./urandom

View File

@@ -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);
} }
} }