Generate random UNIX timestamp (JAVA)

#Generate random UNIX timestamp segment (JAVA)

@(Project_JDBC) In a
recent project, you need to use java to generate the timestamp you want. It is only used to generate the data set, so it is simple and best hhhhh.

##Claim

  1. Time from May 1, 2019 to June 1, 2019
  2. Control the maximum time difference yourself (the size of the data set obtained)
  3. Accuracy: seconds

##Idea

  1. Use online tools to generate the start time and end time for
    UNIX online generation
  2. Use the Random class to generate random numbers and get a random number

Generate a random number from 0-100

import java.util.Random;

public class RandomTest{
    public static void main(String[] args){
        Random rand=new Random();
        int i=(int)(Math.random()*100);       //  生成0-100的随机数,包括0不包括100 -- (0,100]
        int j=rand.nextInt(100);              // 这里是一个方法的重载,参数的内容是指定范围
        System.out.println("i:"+i+"\nj:"+j); // 分别输出两个随机数
    }
}
  1. Use addition and judgment statements to generate UNXI timestamps

##Code

import java.util.Random;

public class Test {
    public static void main(String[] args) {
        Random ra = new Random();
        int cout = 0;
        for (int i = 1556640000; i < 1559318400; i++) {
            int randnum = ra.nextInt(1000);
            i += randnum;//i为所需的时间戳
            cout++;
            System.out.println(i);
        }
        System.out.println(cout);
    }
}

Guess you like

Origin blog.csdn.net/qq_43085611/article/details/93229399