zoukankan      html  css  js  c++  java
  • Java中生成随机字符的方法总结

    package learnExercise;
    
    public class RandomCharacter {
        public static char getRandomCharacter(char ch1,char ch2){
            return (char)(ch1+Math.random()*(ch2-ch1+1));//因为random<1.0,所以需要+1,才能取到ch2
        }
        public static char getRandomLowerCaseLetter(){
            return getRandomCharacter('a','z');
        }
        public static char getRandomUpperCaseLetter(){
            return getRandomCharacter('A','Z');
        }
        public static char getRandomDigitLetter(){
            return getRandomCharacter('0','9');
        }
        
        public static char getRandomCharacter(){
            return getRandomCharacter('u0000','uFFFF');
        }
    }

    上面记录的是生成不同区间随机字符的方法。

    如果您觉得感兴趣的话,可以添加我的微信公众号:一步一步学Python
  • 相关阅读:
    java反编译工具
    javascript
    微信小程序
    微信小程序
    微信小程序
    微信小程序
    微信小程序
    微信小程序
    微信小程序
    微信小程序
  • 原文地址:https://www.cnblogs.com/xingzhui/p/5699914.html
Copyright © 2011-2022 走看看