All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dahuatech.icc.multiinone.utils.RandomUtils Maven / Gradle / Ivy

The newest version!
package com.dahuatech.icc.multiinone.utils;

import java.util.Random;

/**
 * program:sdkTestCase1
 *
 * @Author: 312013
 * @Date:2022-08-24 10:48
 * @Description: 随机数生成类
 */
public class RandomUtils {

    /**
     * 生成指定位数的数字字符串
     * **/
    public static String generateDigitString(Integer digit){
        String res = "";
        Random random = new Random();
        for(int i = 0; i < digit; i++){
            res += random.nextInt(10);
        }
        return res;
    }

    /**
     * 生成指定位数的字母字符串
     * **/
    public static String generateCarsString(Integer digit){
        String res = "";
        char[] str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
        Random random = new Random();
        for(int i = 0; i < digit; i++){
            int t = random.nextInt(52);
            res += str[t];
        }
        return res;
    }



    public static void main(String[] args) {
        System.out.println(generateDigitString(6));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy