package com;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class TestLuckyNum {
public static final SimpleDateFormat sdfTime = new SimpleDateFormat("ssS");
public static void main(String[] args) {
System.out.println(getRandomReqSn("###"));
}
/**
* 取随机数
* @param PrtNo 投保书确认号
* @return
*/
private static String getRandomReqSn(String PrtNo){
Random ran = new Random();
int bitField = 0;
char[] chs = new char[4];
for (int i = 0; i < 4; i++) {
while(true) {
int k = ran.nextInt(10);
if( (bitField & (1 << k)) == 0) {
bitField |= 1 << k;
chs[i] = (char)(k + '0');
break;
}
}
}
//投保书确认号 + 当前时间 hhmmss + 4位随机数
String randomReqSn = PrtNo.trim()+sdfTime.format(new Date())+new String(chs);
return randomReqSn;
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class TestLuckyNum {
public static final SimpleDateFormat sdfTime = new SimpleDateFormat("ssS");
public static void main(String[] args) {
System.out.println(getRandomReqSn("###"));
}
/**
* 取随机数
* @param PrtNo 投保书确认号
* @return
*/
private static String getRandomReqSn(String PrtNo){
Random ran = new Random();
int bitField = 0;
char[] chs = new char[4];
for (int i = 0; i < 4; i++) {
while(true) {
int k = ran.nextInt(10);
if( (bitField & (1 << k)) == 0) {
bitField |= 1 << k;
chs[i] = (char)(k + '0');
break;
}
}
}
//投保书确认号 + 当前时间 hhmmss + 4位随机数
String randomReqSn = PrtNo.trim()+sdfTime.format(new Date())+new String(chs);
return randomReqSn;
}
}