因为测试过程中需要不断用到不同的手机号码,加上本人有选择困难症,故此直接用代码生成随机号码,以免让自己犹豫应该输入哪个手机码号~觉得让自己随意选择号码跟给小孩取名的难度是一样一样的。
java:
package main;import java.util.ArrayList;import java.util.Random;/** * @author 苏宝伢 E-mail:by.su@qq.com * @version 创建时间: 2017年6月6日 下午4:04:58 */public class MobileRandomNum { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(startMobileNo() + endMobileNo()); } public static int startMobileNo(){ int[] mobileStart = {139,138,137,136,135,134,159,158,157,150,151,152,188,130,131,132,156,155,133,153,189,180,177,176}; Random r = new Random(); ArrayListmobileList = new ArrayList<>(); for(int i = 0;i
-----------------------------华丽的分割线--------------------------------------------------------
R语言
#生成手机号码前部分my.mobileNoStart <- function(position){ return(c(139,138,137,136,135,134,159,158,157,150,151,152,188,130,131,132,156,155,133,153,189,180,177,176)[position])}#生成手机号码后部分my.mobileNoEnd <- function(length){ endNo <- sample(0:9, size = length) i <- "" for(k in endNo){ i <- paste(i,as.character(k)) }# i <- gsub(" ","",i) return(i)}#合成手机号码my.mobileNo.paste <- function(){ random.position <- round(runif(1,1,length(my.mobileNoStart()))) mobileStartNo <- as.character(my.mobileNoStart(random.position)) mobileEndNo <- as.character(my.mobileNoEnd(8)) gsub(" ","",paste(mobileStartNo,mobileEndNo))}print(my.mobileNo.paste())
------------Java实现随机生成姓名(姓氏我就挑了几个常见的)-----------------------------------------------
package my_work_tool;import java.io.UnsupportedEncodingException;import java.util.Random;import java.util.List;import java.util.ArrayList;import java.util.regex.Matcher;import java.util.regex.Pattern;/** * @author 苏宝伢 E-mail:by.su@qq.com * @version 创建时间: 2017年6月8日 上午9:46:36 */public class RandomName { public static void main(String[] args) throws UnsupportedEncodingException { String[] firstName = {"赵","钱","孙","李","周","吴","郑","王","冯","陈","卫","蒋","沈","韩","杨","朱","秦","许","何","吕","施","张","孔","曹","严","华","金","魏","陶","云","苏","范","彭","乐","于","时","傅","皮","齐","康","梅","林","刁","钟","徐","邱","骆"}; System.out.print(firstName[randomPositon(firstName.length)]); System.out.println(hexIntToHexString("\\u" + randomName())); } public static int randomPositon(int length){ Random r = new Random(); return r.nextInt(length); } public static ListallGB(){ ArrayList resultList = new ArrayList<>(); for(int i = 0x4E00;i <= 0x9FA5;i++){ resultList.add(Integer.toHexString(i)); } return resultList; } public static String randomName(){ ArrayList resultList = (ArrayList )allGB(); return resultList.get(randomPositon(resultList.size())); } public static String hexIntToHexString(String hexno){ if(hexno.contains("\\u")) { StringBuffer buf = new StringBuffer(); Matcher m = Pattern.compile("\\\\u([0-9A-Fa-f]{4})").matcher(hexno); while (m.find()) { try { int cp = Integer.parseInt(m.group(1), 16); m.appendReplacement(buf, ""); buf.appendCodePoint(cp); } catch (NumberFormatException e) { } } m.appendTail(buf); String result = buf.toString(); return result; }else{ return null; } }}