其他分享
首页 > 其他分享> > 随机手机号

随机手机号

作者:互联网

方法一:

//定义手机号前3位
String[] FirstThreeNumber = {"134","135","136","137","138","139","147","150","152","157","158","159","172","178","182","183","184","187","188","198","130","131","132","145","155","156","166","171","175","176","185","186","166","133","149","153","173","177","180","181","189","199"};
 
//随机获取前三位手机号的index
int n= (int)(Math.random() * FirstThreeNumber.length);
//int n= (int)(Math.random()*(3-1)+1); //设置一个1到3的变量
//int n= (int)(Math.random()*5);  //设置一个0到4的变量

//获取手机前三位
String yy = FirstThreeNumber[n];
//循环获取手机号后8位
for(int i = 0; i < 8; i++){
	int x = (int)(Math.random() * 9); //设置一个0到8的变量
	yy = yy + x;
};
vars.put("com_phone", yy);

 

方法二:

//现在设置一个用户初始变量手机号,然后在这里获取
String aa=vars.get("beginPhone");

//log.info("获取手机号: "+aa);

Long phone2 =Long.valueOf(aa);

//每次加一
phone2 = phone2+1;

String newPhone=String.valueOf(phone2);

//log.info(newPhone);

vars.put("beginPhone",newPhone);

 

标签:String,int,yy,phone2,随机,Math,手机号
来源: https://www.cnblogs.com/kaibindirver/p/16516084.html