`
kingmxj
  • 浏览: 182537 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

生成八位随机数(含有大小写字母和数字)

    博客分类:
  • Java
阅读更多
List list = new ArrayList();
           // list.add(1);
           for (int i = 0; i < 10; i++)
                   list.add(i+"");

           for (char c = 'a'; c <= 'z'; c++)
                   list.add(c+"");
           for (char c = 'A'; c <= 'Z'; c++)
               list.add(c+"");

           String randomStr = "";
         
           for (int i = 0; i < 8; i++) {
                   int mathInt;
                   mathInt=(int) (Math.random()*list.size());
                   randomStr +=(String)list.get(mathInt);
                   list.remove(mathInt);
           }
          
           System.out.println(randomStr);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics