How to generate a random alpha-numeric string

前端 未结 30 2431
忘掉有多难
忘掉有多难 2020-11-21 05:38

I\'ve been looking for a simple Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifie

30条回答
  •  隐瞒了意图╮
    2020-11-21 06:02

    import java.util.Date;
    import java.util.Random;
    
    public class RandomGenerator {
    
      private static Random random = new Random((new Date()).getTime());
    
        public static String generateRandomString(int length) {
          char[] values = {'a','b','c','d','e','f','g','h','i','j',
                   'k','l','m','n','o','p','q','r','s','t',
                   'u','v','w','x','y','z','0','1','2','3',
                   '4','5','6','7','8','9'};
    
          String out = "";
    
          for (int i=0;i

提交回复
热议问题