zoukankan      html  css  js  c++  java
  • 产生随机数和随机字母的工具类

    package com.souvc.utils;
    
    public class RandomGenerator {
        public RandomGenerator() {
        }
        public static String getRandomNum(int number){
            String password = "";
            for (int i = 0; i < number; i++) {
                String rand = String.valueOf((int) (Math.random() * 10));
                password += rand;
    
            }
            return password;
    
        }
        public static String getRandom8Num() {
            String password = "";
            for (int i = 0; i < 8; i++) {
                String rand = String.valueOf((int) (Math.random() * 10));
                password += rand;
    
            }
            return password;
        }
        public static String randomPassword() {
            return randomString(6);
        }
    
        public static String randomString(int length) {
            return randomString(length, true);
        }
    
        public static String randomString(int length, boolean includeNumbers) {
            StringBuffer b = new StringBuffer(length);
            for (int i = 0; i < length; i++)
                if (includeNumbers)
                    b.append(randomCharacter());
                else
                    b.append(randomAlpha());
            return b.toString();
        }
    
        public static char randomCharacter() {
            int i = (int) (Math.random() * 3D);
            if (i < 2)
                return randomAlpha();
            else
                return randomDigit();
        }
    
        public static char randomAlpha() {
            int i = (int) (Math.random() * 52D);
            if (i > 25)
                return (char) ((97 + i) - 26);
            else
                return (char) (65 + i);
        }
    
        public static char randomDigit() {
            int i = (int) (Math.random() * 10D);
            return (char) (48 + i);
        }
        public static void main(String[] args) {
            System.out.println(getRandom8Num());
        }
    }
  • 相关阅读:
    并行取数提升报表性能
    报表选型中那些想不到的坑
    原来报表可以做这么多动态交互效果
    多折线堆叠图如何制作?
    SSIS文档导入DB中文乱码
    Linux-系统日志
    linux-用户和组的管理
    LInux-用户和用户组
    dotcore发布到IIS
    vue发布
  • 原文地址:https://www.cnblogs.com/liuhongfeng/p/4543921.html
Copyright © 2011-2022 走看看