From a82eef1afe9fde25cb138d3a0932b7499de7e497 Mon Sep 17 00:00:00 2001 From: Jesse-Ma <24167796@qq.com> Date: Mon, 26 Dec 2022 11:07:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ .../java/com/flagnote/note/utils/RandomUtils.java | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 277c640..58b1064 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # flagnote-service flagnote-service + +-Djava.security.egd=file:/dev/./urandom diff --git a/src/main/java/com/flagnote/note/utils/RandomUtils.java b/src/main/java/com/flagnote/note/utils/RandomUtils.java index 1ccc72b..4c565eb 100644 --- a/src/main/java/com/flagnote/note/utils/RandomUtils.java +++ b/src/main/java/com/flagnote/note/utils/RandomUtils.java @@ -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); } } \ No newline at end of file