yumeng 5 年之前
父节点
当前提交
f9ff17a49d
共有 1 个文件被更改,包括 31 次插入0 次删除
  1. 31 0
      module-common/src/main/java/cn/com/ctop/common/module/utils/RandomUtil.java

+ 31 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/RandomUtil.java

@@ -0,0 +1,31 @@
+package cn.com.ctop.common.module.utils;
+
+import java.util.Random;
+
+public class RandomUtil {
+
+    public static String verifyCode() {
+
+        char[] c = charArray();//获取包含26个字母大小写和数字的字符数组
+
+        Random rd = new Random();
+        String code = "_";
+        for (int k = 0; k <= 4; k++) {
+            int index = rd.nextInt(c.length);//随机获取数组长度作为索引
+            code += c[index];//循环添加到字符串后面
+        }
+        return code;
+    }
+
+
+    private static char[] charArray() {
+        int i = 1234567890;
+        String s = "qwertyuiopasdfghjklzxcvbnm";
+        String S = s.toUpperCase();
+        String word = s + S + i;
+        char[] c = word.toCharArray();
+
+        return c;
+    }
+
+}