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
  • 相关阅读:
    RQNOJ 1 明明的随机数
    poj1284
    poj1061
    51nod1305
    51nod 1344
    poj2240
    poj1860
    使用SwitchToThisWindow时不切换问题
    c#拷贝整个文件夹到指定文件夹下(非递归)
    IniHelper
  • 原文地址:https://www.cnblogs.com/xingzhui/p/5699914.html
Copyright © 2011-2022 走看看