#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
- Time from May 1, 2019 to June 1, 2019
- Control the maximum time difference yourself (the size of the data set obtained)
- Accuracy: seconds
##Idea
- Use online tools to generate the start time and end time for
UNIX online generation - 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); // 分别输出两个随机数
}
}
- 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);
}
}