From c313a253b1fcdc75b6be5db575fc2b29fb407021 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期三, 15 四月 2026 20:05:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
server/services/src/main/java/com/doumee/core/utils/RandomString.java | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/server/services/src/main/java/com/doumee/core/utils/RandomString.java b/server/services/src/main/java/com/doumee/core/utils/RandomString.java
new file mode 100644
index 0000000..7b407cd
--- /dev/null
+++ b/server/services/src/main/java/com/doumee/core/utils/RandomString.java
@@ -0,0 +1,60 @@
+package com.doumee.core.utils;
+
+import java.security.SecureRandom;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.Random;
+
+public class RandomString {
+
+ protected static final String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ protected static final String lower = upper.toLowerCase(Locale.ROOT);
+ protected static final String digits = "0123456789";
+ protected static final String alphaNumeric = upper + lower + digits;
+ private final Random random;
+ private final char[] symbols;
+ private final char[] buf;
+
+ public RandomString(int length, Random random, String symbols) {
+ if (length < 1) {
+ throw new IllegalArgumentException();
+ }
+ if (symbols.length() < 2) {
+ throw new IllegalArgumentException();
+ }
+ this.random = Objects.requireNonNull(random);
+ this.symbols = symbols.toCharArray();
+ this.buf = new char[length];
+ }
+
+ /**
+ * Create an alphanumeric string generator.
+ */
+ public RandomString(int length, Random random) {
+ this(length, random, alphaNumeric);
+ }
+
+ /**
+ * Create an alphanumeric strings from a secure generator.
+ */
+ public RandomString(int length) {
+ this(length, new SecureRandom());
+ }
+
+ /**
+ * Create session identifiers.
+ */
+ public RandomString() {
+ this(21);
+ }
+
+ /**
+ * Generate a random string.
+ */
+ public String nextString() {
+ for (int idx = 0; idx < buf.length; ++idx) {
+ buf[idx] = symbols[random.nextInt(symbols.length)];
+ }
+ return new String(buf);
+ }
+}
--
Gitblit v1.9.3