Java: generate non-repeating six-digit random numbers

A customer code and registration time are used, so that when I add customer information, it will be automatically generated immediately. The code is stuck here. If it is useful to you, I hope it can help you: 
1) Generate a six-digit number I wrote a tool class RandomStringUtil.java along with the customer code string, which is ready to use:

import java.util.Random;

/**
 * 产生随机字符串,长度由参数指定。
 * @param length 产生的字符串的长度
 * @return 已产生的字符串
 * @author Code_小生
 */
public class RandomStringUtil {

    public static String getRandString(int length)
    {
        String charList = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        String rev = "";
        Random f = new Random();
        for(int i=0;i<length;i++)
        {
           rev += charList.charAt(Math.abs(f.nextInt())%charList.length());
        }
        return rev;
    }
}

 

Guess you like

Origin blog.csdn.net/sulu0416/article/details/88094556