cn.bif.common.RandomNonceUtils Maven / Gradle / Ivy
The newest version!
package cn.bif.common;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class RandomNonceUtils {
public static void main(String[] args) {
System.out.println(randomNonce());
System.out.println(getRangeRandom(20,200));
}
public static Long randomNonce() {
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
Random r = new Random();
int random = r.nextInt(100);
String randomNonce = timestamp + random;
return Long.parseLong(randomNonce);
}
public static String getRandom(int len) {
Random r = new Random();
StringBuilder rs = new StringBuilder();
for (int i = 0; i < len; i++) {
rs.append(r.nextInt(10));
}
return rs.toString();
}
public static int getRangeRandom(int min,int max){
Random r = new Random();
int s = r.nextInt(max)%(max-min+1)+min;
return s;
}
public static int getDefaultRangeRandom(){
int min = 100;
int max = 2000;
return getRangeRandom(min,max);
}
}