JAVA获取5位随机数

时间:2024-03-11 13:09:23
package baofoo.utils;

import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.logging.SimpleFormatter;

/**
 * 2 * @Author: zhangting_li
 * 3 * @Date: 2019/4/1 17:35
 * 4
 */

public class RandomHelper {
    public static String getRandom(){
        SimpleDateFormat simpleDateFormat;
        simpleDateFormat=new SimpleDateFormat("yyyyMMdd");
        String date=simpleDateFormat.format(new Date());
        Random random=new Random();
      int rannum= (int)(random.nextDouble()*(99999-10000 + 1))+ 10000;
       // System.out.println(rannum);
      String rand=date+rannum;
      return rand;
    }

}