[Java] 动态生成n位随机字符数组 →→→→→进入此内容的聊天室

来自 , 2019-03-02, 写在 Java, 查看 156 次.
URL http://www.code666.cn/view/5751ec3e
  1. /**
  2.  * 动态生成n位随机字符数组
  3.  *
  4.  * @author 苏持恒
  5.  */
  6. public class ShortMessageCodeUntil
  7. {
  8.  
  9.  
  10.     /**
  11.      * 随机生成4位数字字符数组
  12.      *
  13.      * @return rands
  14.      */
  15.     public static char[] generateCheckCode()
  16.     {
  17.         String chars = "0123456789";
  18.         char[] rands = new char[4];
  19.         for (int i = 0; i < 4; i++)
  20.         {
  21.             int rand = (int) (Math.random() * 10);
  22.             rands[i] = chars.charAt (rand);
  23.         }
  24.         return rands;
  25.     }
  26.  
  27.  
  28.     /**
  29.      * 随机生成6位数字字符数组
  30.      *
  31.      * @return rands
  32.      */
  33.     public static char[] generateCheckPass()
  34.     {
  35.         String chars = "0123456789";
  36.         char[] rands = new char[6];
  37.         for (int i = 0; i < 6; i++)
  38.         {
  39.             int rand = (int) (Math.random() * 10);
  40.             rands[i] = chars.charAt (rand);
  41.         }
  42.         return rands;
  43.     }
  44.  
  45.  
  46. }

回复 "动态生成n位随机字符数组"

这儿你可以回复上面这条便签

captcha