简单易用的随机数据生成器。一般用于开发和测试阶段的数据填充、模拟、仿真研究、演示等场景。
可以集成到各种类型的java项目中使用。
<dependency>
<groupId>com.apifan.commongroupId>
<artifactId>common-randomartifactId>
<version>1.0.19version>
dependency>
//地区类虚拟数据
AreaSource areaSource = RandomSource.areaSource();
//日期时间类虚拟数据
DateTimeSource dateTimeSource = RandomSource.dateTimeSource();
//教育类虚拟数据
EducationSource educationSource = RandomSource.educationSource();
//金融类虚拟数据
FinancialSource financialSource = RandomSource.financialSource();
//互联网信息类虚拟数据
InternetSource internetSource = RandomSource.internetSource();
//数字类虚拟数据
NumberSource numberSource = RandomSource.numberSource();
//个人类虚拟数据
PersonInfoSource personInfoSource = RandomSource.personInfoSource();
//体育竞技类虚拟数据
SportSource sportSource = RandomSource.sportSource();
//语言文字类虚拟数据
LanguageSource languageSource = RandomSource.languageSource();
//其它杂项虚拟数据
OtherSource otherSource = RandomSource.otherSource();
// 生成1个1~101(不含)之间的随机整数
int anInt = RandomSource.numberSource().randomInt(1, 101);
System.out.println("anInt = " + anInt);
// 生成8个1~101(不含)之间的随机整数
int[] anInt2 = RandomSource.numberSource().randomInt(1, 101, 8);
List<Integer> anInt2s = IntStream.of(anInt2).mapToObj(i -> i).collect(Collectors.toList());
System.out.println("anInt2s = " + anInt2s);
// 生成1个10000000000~20000000001(不含)之间的随机长整数
long aLong = RandomSource.numberSource().randomLong(10000000000L, 20000000001L);
System.out.println("aLong = " + aLong);
// 生成9个10000000000~20000000001(不含)之间的随机长整数
long[] aLong2 = RandomSource.numberSource().randomLong(10000000000L, 20000000001L, 9);
List<Long> aLong2s = LongStream.of(aLong2).mapToObj(l -> l).collect(Collectors.toList());
System.out.println("aLong2s = " + aLong2s);
// 生成1个0.01~0.51(不含)之间的随机整数
double aDouble = RandomSource.numberSource().randomDouble(0.01D, 0.51D);
System.out.println("aDouble = " + aDouble);
// 生成8个0.01~0.51(不含)之间的随机整数
double[] aDouble2 = RandomSource.numberSource().randomDouble(0.01D, 0.51D, 8);
List<Double> aDouble2s = DoubleStream.of(aDouble2).mapToObj(d -> d).collect(Collectors.toList());
System.out.println("aDouble2s = " + aDouble2s);
// 生成随机百分比
BigDecimal percent = RandomSource.numberSource().randomPercent();
System.out.println("percent = " + percent);
// 生成1个随机汉字
String randomChinese = RandomSource.languageSource().randomChinese();
System.out.println("randomChinese = " + randomChinese);
// 生成4个随机汉字
String randomChinese2 = RandomSource.languageSource().randomChinese(4);
System.out.println("randomChinese2 = " + randomChinese2);
String idiom = RandomSource.languageSource().randomChineseIdiom();
System.out.println("idiom = " + idiom);
Poem tangPoem = RandomSource.languageSource().randomTangPoem();
System.out.println("tangPoem = " + tangPoem);
// 生成1个随机中文人名(性别随机)
String chineseName = RandomSource.personInfoSource().randomChineseName();
System.out.println("chineseName = " + chineseName);
// 生成1个随机男性中文人名
String maleChineseName = RandomSource.personInfoSource().randomMaleChineseName();
System.out.println("maleChineseName = " + maleChineseName);
// 生成1个随机女性中文人名
String femaleChineseName = RandomSource.personInfoSource().randomFemaleChineseName();
System.out.println("femaleChineseName = " + femaleChineseName);
// 生成1个随机英文人名
String englishName = RandomSource.personInfoSource().randomEnglishName();
System.out.println("englishName = " + englishName);
// 生成1个随机的虚拟身份证号码,地区为广西壮族自治区,男性,出生日期在1990年11月11日至1999年12月12日之间
LocalDate beginDate = LocalDate.of(1990,11,11);
LocalDate endDate = LocalDate.of(1999,12,12);
String idCard = RandomSource.personInfoSource().randomMaleIdCard(Province.GX, beginDate, endDate);
System.out.println("idCard = " + idCard);
// 生成1个随机的虚拟身份证号码,地区为河北省,女性,出生日期在2001年1月11日至2008年2月22日之间
LocalDate beginDate2 = LocalDate.of(2001,1,11);
LocalDate endDate2 = LocalDate.of(2008,2,22);
String idCard2 = RandomSource.personInfoSource().randomFemaleIdCard(Province.HE, beginDate2, endDate2);
System.out.println("idCard2 = " + idCard2);
// 生成1个随机的虚拟身份证号码,地区为广西壮族自治区,男性,年龄为18岁
String idCard3 = RandomSource.personInfoSource().randomMaleIdCard(Province.GX, 18);
System.out.println("idCard3 = " + idCard3);
// 生成1个随机的虚拟身份证号码,地区为河北省,女性,年龄为19岁
String idCard4 = RandomSource.personInfoSource().randomFemaleIdCard(Province.HE, 19);
System.out.println("idCard4 = " + idCard4);
注意:
- 身份证号码前6位地区码数据取自民政部网站2019年公开数据
- 随机生成的虚拟身份证号码符合校验规则,但有可能与真实号码相同(纯属巧合)
// 生成1个随机虚拟VISA信用卡号码
String cardNoOfVisa = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.Visa);
System.out.println("cardNoOfVisa = " + cardNoOfVisa);
// 生成1个随机虚拟MasterCard信用卡号码
String cardNoOfMasterCard = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.MasterCard);
System.out.println("cardNoOfMasterCard = " + cardNoOfMasterCard);
// 生成1个随机虚拟American Express信用卡号码
String cardNoOfAmex = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.Amex);
System.out.println("cardNoOfAmex = " + cardNoOfAmex);
// 生成1个随机虚拟银联信用卡号码
String cardNoOfUnionPay = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.UnionPay);
System.out.println("cardNoOfUnionPay = " + cardNoOfUnionPay);
// 生成1个随机虚拟JCB信用卡号码
String cardNoOfJCB = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.JCB);
System.out.println("cardNoOfJCB = " + cardNoOfJCB);
注意:
- 随机生成的虚拟银行卡号码只是前缀和位数符合规则,不会与现实中的真实卡号产生重合,无法用于支付,仅供模拟测试/仿真/项目演示等用途
// 生成1个随机中国大陆手机号
String chineseMobile = RandomSource.personInfoSource().randomChineseMobile();
System.out.println("chineseMobile = " + chineseMobile);
// 生成1个随机邮箱地址,后缀随机,邮箱用户名最大长度为10
String randomEmail = RandomSource.internetSource().randomEmail(10);
System.out.println("randomEmail = " + randomEmail);
// 生成1个随机邮箱地址,后缀为163.com,邮箱用户名最大长度为10
String randomEmail2 = RandomSource.internetSource().randomEmail(10, "163.com");
System.out.println("randomEmail2 = " + randomEmail2);
// 生成1个随机域名,域名最大长度为16
String randomDomain = RandomSource.internetSource().randomDomain(16);
System.out.println("randomDomain = " + randomDomain);
// 生成1个随机公网IPv4地址
String publicIpv4 = RandomSource.internetSource().randomPublicIpv4();
System.out.println("publicIpv4 = " + publicIpv4);
// 生成1个随机私有(内网)IPv4地址
String privateIpv4 = RandomSource.internetSource().randomPrivateIpv4();
System.out.println("privateIpv4 = " + privateIpv4);
// 生成1个随机ipv6地址
String randomIpV6 = RandomSource.internetSource().randomIpV6();
System.out.println("randomIpV6 = " + randomIpV6);
// 生成1个随机端口号
int randomPort = RandomSource.internetSource().randomPort();
System.out.println("randomPort = " + randomPort);
// 生成1个随机App名称
String randomAppName = RandomSource.internetSource().randomAppName();
System.out.println("randomAppName = " + randomAppName);
// 生成1个随机App Bundle ID
String randomAppBundleId = RandomSource.internetSource().randomAppBundleId();
System.out.println("randomAppBundleId = " + randomAppBundleId);
// 生成1个随机App版本号
String randomAppVersionCode = RandomSource.internetSource().randomAppVersionCode();
System.out.println("randomAppVersionCode = " + randomAppVersionCode);
// 生成1个随机静态url,后缀为jpg
String randomStaticUrl = RandomSource.internetSource().randomStaticUrl("jpg");
System.out.println("randomStaticUrl = " + randomStaticUrl);
// 生成1个2020年的随机日期,日期格式为yyyy-MM-dd
String randomDate = RandomSource.dateTimeSource().randomDate(2020, "yyyy-MM-dd");
System.out.println("randomDate = " + randomDate);
// 生成1个2020年1月2日之后的随机日期,日期格式为yyyy-MM-dd
String randomFutureDate = RandomSource.dateTimeSource().randomFutureDate(LocalDate.of(2020, 1, 2), "yyyy-MM-dd");
System.out.println("randomFutureDate = " + randomFutureDate);
// 生成1个今天(基于系统时间判断)之后的随机日期,日期格式为yyyy-MM-dd
String randomFutureDate2 = RandomSource.dateTimeSource().randomFutureDate("yyyy-MM-dd");
System.out.println("randomFutureDate2 = " + randomFutureDate2);
// 生成1个2020年1月2日之前1年内的随机日期,日期格式为yyyy-MM-dd
String randomPastDate = RandomSource.dateTimeSource().randomPastDate(LocalDate.of(2020, 1, 2), "yyyy-MM-dd");
System.out.println("randomPastDate = " + randomPastDate);
// 生成1个今天(基于系统时间判断)之前1年内的随机日期,日期格式为yyyy-MM-dd
String randomPastDate2 = RandomSource.dateTimeSource().randomPastDate("yyyy-MM-dd");
System.out.println("randomPastDate2 = " + randomPastDate2);
// 生成1个2020年1月2日之前10年内的随机日期,日期格式为yyyy-MM-dd
String randomPastDate3 = RandomSource.dateTimeSource().randomPastDate(LocalDate.of(2020, 1, 2), 3650, "yyyy-MM-dd");
System.out.println("randomPastDate3 = " + randomPastDate3);
// 生成1个2000年1月11日至2010年2月22日范围之间的随机日期,日期格式为yyyy-MM-dd
LocalDate beginDate = LocalDate.of(2000, 1, 11);
LocalDate endDate = LocalDate.of(2010, 2, 22);
String randomDate2 = RandomSource.dateTimeSource().randomDate(beginDate, endDate, "yyyy-MM-dd");
System.out.println("randomDate2 = " + randomDate2);
// 生成过去7天范围内的随机时间
LocalDateTimerandomPastTime = RandomSource.dateTimeSource().randomPastTime(7);
System.out.println("randomPastTime = " + randomPastTime);
// 生成未来7天范围内的随机时间
LocalDateTime randomFutureTime = RandomSource.dateTimeSource().randomFutureTime(7);
System.out.println("randomFutureTime = " + randomFutureTime);
// 生成2020年2月14日当天范围内的随机时间
LocalDateTime randomTime = RandomSource.dateTimeSource().randomTime(2020, 2, 14);
System.out.println("randomTime = " + randomTime);
// 生成过去100秒范围内的随机时间
LocalDateTime randomPastTime2 = RandomSource.dateTimeSource().randomPastTime(LocalDateTime.now(), 100);
System.out.println("randomPastTime2 = " + randomPastTime2);
// 生成未来100秒范围内的随机时间
LocalDateTime randomFutureTime2 = RandomSource.dateTimeSource().randomFutureTime(LocalDateTime.now(), 100);
System.out.println("randomFutureTime2 = " + randomFutureTime2);
// 生成1个当天范围内的随机时间戳
long randomTimestamp = RandomSource.dateTimeSource().randomTimestamp(LocalDate.now());
System.out.println("randomTimestamp = " + randomTimestamp);
// 生成1个2020年3月6日范围内的随机时间戳
long randomTimestamp2 = RandomSource.dateTimeSource().randomTimestamp(LocalDate.of(2020, 3, 6));
System.out.println("randomTimestamp2 = " + randomTimestamp2);
// 生成1个介于2020年3月6日12:00:00至2020年3月6日12:30:00之间的随机时间戳
LocalDateTime begin = LocalDateTime.of(2020, 3, 6, 12, 0, 0);
LocalDateTime end = LocalDateTime.of(2020, 3, 6, 12, 30, 0);
long randomTimestamp3 = RandomSource.dateTimeSource().randomTimestamp(begin, end);
System.out.println("randomTimestamp3 = " + randomTimestamp3);
// 生成1个2020年3月6日12:00:00之后180秒内的随机时间戳
LocalDateTime base1 = LocalDateTime.of(2020, 3, 6, 12, 0, 0);
long randomFutureTimestamp = RandomSource.dateTimeSource().randomFutureTimestamp(base1, 180);
System.out.println("randomFutureTimestamp = " + randomFutureTimestamp);
// 生成1个2020年3月7日13:00:00之前120秒内的随机时间戳
LocalDateTime base2 = LocalDateTime.of(2020, 3, 7, 13, 0, 0);
long randomPastTimestamp = RandomSource.dateTimeSource().randomPastTimestamp(base2, 120);
System.out.println("randomPastTimestamp = " + randomPastTimestamp);
// 生成1个随机时区名称
String randomTimezoneName = RandomSource.dateTimeSource().randomTimezoneName();
System.out.println("randomTimezoneName = " + randomTimezoneName);
// 生成1个随机强密码,长度为16,无特殊字符
String randomStrongPassword = RandomSource.personInfoSource().randomStrongPassword(16, false);
System.out.println("randomStrongPassword = " + randomStrongPassword);
// 生成1个随机强密码,长度为16,有特殊字符
String randomStrongPassword2 = RandomSource.personInfoSource().randomStrongPassword(16, true);
System.out.println("randomStrongPassword2 = " + randomStrongPassword2);
// 随机获取省份
String randomProvince = RandomSource.areaSource().randomProvince();
System.out.println("randomProvince = " + randomProvince);
// 随机获取城市(省份+城市,以逗号为分隔符)
String randomCity = RandomSource.areaSource().randomCity(",");
System.out.println("randomCity = " + randomCity);
// 随机获取邮编
String randomZipCode = RandomSource.areaSource().randomZipCode();
System.out.println("randomZipCode = " + randomZipCode);
// 生成1个随机中国大陆详细地址
String randomAddress = RandomSource.areaSource().randomAddress();
System.out.println("randomAddress = " + randomAddress);
// 随机获取1个编码首字母为b的国家或地区
CountryOrRegionCode countryOrRegionCode = RandomSource.areaSource().randomCountryOrRegionCode("b");
System.out.println("countryOrRegionCode = " + countryOrRegionCode);
// 随机获取1个国家或地区(不限首字母)
CountryOrRegionCode countryOrRegionCode2 = RandomSource.areaSource().randomCountryOrRegionCode();
System.out.println("countryOrRegionCode2 = " + countryOrRegionCode2);
// 随机生成1个纬度
double randomLatitude = RandomSource.areaSource().randomLatitude();
System.out.println("randomLatitude = " + randomLatitude);
// 随机生成1个经度
double randomLongitude = RandomSource.areaSource().randomLongitude();
System.out.println("randomLongitude = " + randomLongitude);
// 随机固话区号(省级行政区名称不需要包含后缀)
String randomPhoneCode = RandomSource.areaSource().randomPhoneCode("湖南");
System.out.println("randomPhoneCode = " + randomPhoneCode);
// 随机固话号码(使用-作为分隔符,默认的分隔符是空格)
String randomPhoneNumber = RandomSource.areaSource().randomPhoneNumber("广东", "-");
System.out.println("randomPhoneNumber = " + randomPhoneNumber);
// 生成1个随机中国大陆车牌号(新能源车型)
String randomPlateNumber = RandomSource.otherSource().randomPlateNumber(true);
System.out.println("randomPlateNumber = " + randomPlateNumber);
// 生成1个随机中国大陆车牌号(非新能源车型)
String randomPlateNumber2 = RandomSource.otherSource().randomPlateNumber();
System.out.println("randomPlateNumber2 = " + randomPlateNumber2);
// 生成1个随机英文网络昵称,最大长度为8个字符
String randomNickName = RandomSource.personInfoSource().randomNickName(8);
System.out.println("randomNickName = " + randomNickName);
// 生成1个随机汉字网络昵称,最大长度为8个汉字
String randomChineseNickName = RandomSource.personInfoSource().randomChineseNickName(8);
System.out.println("randomChineseNickName = " + randomChineseNickName);
// 基于随机汉字网络昵称生成1个拼音网络昵称,最大长度为4个汉字
String randomPinyinNickName = RandomSource.personInfoSource().randomPinyinNickName(4);
System.out.println("randomPinyinNickName = " + randomPinyinNickName);
// 生成1个随机QQ号
String randomQQAccount = RandomSource.personInfoSource().randomQQAccount();
System.out.println("randomQQAccount = " + randomQQAccount);
// 生成1个随机非主流QQ网名
String randomQQNickName = RandomSource.personInfoSource().randomQQNickName();
System.out.println("randomQQNickName = " + randomQQNickName);
String randomEthnicName = RandomSource.otherSource().randomEthnicName();
System.out.println("randomEthnicName = " + randomEthnicName);
// 随机获取学历
String randomDegree = RandomSource.educationSource().randomDegree();
System.out.println("randomDegree = " + randomDegree);
// 随机获取本科高校名称
String randomCollege = RandomSource.educationSource().randomCollege();
System.out.println("randomCollege = " + randomCollege);
// 随机高校专业名称
String randomMajorName = RandomSource.educationSource().randomMajorName();
System.out.println("randomMajorName = " + randomMajorName);
// 随机获取小学名称
String randomPrimarySchoolName = RandomSource.educationSource().randomPrimarySchoolName();
System.out.println("randomPrimarySchoolName = " + randomPrimarySchoolName);
// 随机获取小学年级
String randomPrimarySchoolGrade = RandomSource.educationSource().randomPrimarySchoolGrade();
System.out.println("randomPrimarySchoolGrade = " + randomPrimarySchoolGrade);
// 随机获取中学名称
String randomHighSchoolName = RandomSource.educationSource().randomHighSchoolName();
System.out.println("randomHighSchoolName = " + randomHighSchoolName);
// 随机获取中学年级
String randomHighSchoolGrade = RandomSource.educationSource().randomHighSchoolGrade();
System.out.println("randomHighSchoolGrade = " + randomHighSchoolGrade);
// 随机班级名称
String randomClassName = RandomSource.educationSource().randomClassName();
System.out.println("randomClassName = " + randomClassName);
// 随机生成1个公司名称,地区前缀为北京
String companyName = RandomSource.otherSource().randomCompanyName("北京");
System.out.println("companyName = " + companyName);
// 随机生成1个公司部门名称
String companyDepartment = RandomSource.otherSource().randomCompanyDepartment();
System.out.println("companyDepartment = " + companyDepartment);
// 随机生成1条中文短句
StringchineseSentence = RandomSource.languageSource().randomChineseSentence();
System.out.println("chineseSentence = " + chineseSentence);
// 随机生成1条英文文本,包含10个单词
String randomEnglishText = RandomSource.languageSource().randomEnglishText(10);
System.out.println("randomEnglishText = " + randomEnglishText);
String randomNonsenseTitle = RandomSource.languageSource().randomNonsenseTitle("星期一", "下雨");
System.out.println("randomNonsenseTitle = " + randomNonsenseTitle);
String randomNonsense = RandomSource.languageSource().randomNonsense("星期一", "下雨");
System.out.println("randomNonsense = " + randomNonsense);
EconomicCategory economicCategory = RandomSource.otherSource().randomEconomicCategory();
System.out.println("economicCategory = " + economicCategory);
String socialCreditCode = RandomSource.otherSource().randomSocialCreditCode();
System.out.println("socialCreditCode = " + socialCreditCode);
// 随机ISBN,返回结果需要分隔符-,格式例如:978-7-XXXX-XXXX-X
String randomISBN = RandomSource.otherSource().randomISBN(true);
System.out.println("randomISBN = " + randomISBN);
// 随机ISBN,返回结果不需要分隔符,格式例如:9787XXXXXXXXX
String randomISBN1 = RandomSource.otherSource().randomISBN(false);
System.out.println("randomISBN1 = " + randomISBN1);
// 随机国际商品编码,格式例如:691XXXXXXXXXX
String randomEAN = RandomSource.otherSource().randomEAN();
System.out.println("randomEAN = " + randomEAN);
说明:
- 本程序随机生成的EAN编码长度为13位
- 本程序随机生成的EAN编码符合标准校验规则,仅供模拟测试/仿真/项目演示等用途,并不表示现实中真实存在该编码对应的商品(如有雷同纯属巧合)
// 随机生成1个PC User-Agent
String randomPCUserAgent = RandomSource.internetSource().randomPCUserAgent();
System.out.println("randomPCUserAgent = " + randomPCUserAgent);
// 随机生成1个Android User-Agent
String randomAndroidUserAgent = RandomSource.internetSource().randomAndroidUserAgent();
System.out.println("randomAndroidUserAgent = " + randomAndroidUserAgent);
// 随机生成1个iOS User-Agent
String randomIOSUserAgent = RandomSource.internetSource().randomIOSUserAgent();
System.out.println("randomIOSUserAgent = " + randomIOSUserAgent);
// 随机生成1个网卡MAC地址,使用:作为分隔符
StringmacAddress = RandomSource.internetSource().randomMacAddress(":");
System.out.println("macAddress = " + macAddress);
// 随机生成1个RGB颜色值
int[] randomRgbColor = RandomSource.otherSource().randomRgbColor();
List<Integer> collect = IntStream.of(randomRgbColor).mapToObj(i -> i).collect(Collectors.toList());
System.out.println("collect = " + collect);
// 随机生成1个16进制(HEX)颜色值
String randomHexColor = RandomSource.otherSource().randomHexColor();
System.out.println("randomHexColor = " + randomHexColor);
// 随机股票信息(沪A+深A+创业板+科创版)
String[] stock = RandomSource.financialSource().randomStock();
String stockName = stock[0];
String stockCode = stock[1];
System.out.println("stockName = " + stockName + " -> stockCode = " + stockCode);
// 随机股票信息(港股)
String[] hkStock = RandomSource.financialSource().randomHKStock();
String hkStockName = hkStock[0];
String hkStockCode = hkStock[1];
System.out.println("hkStockName = " + hkStockName + " -> hkStockCode = " + hkStockCode);
// 随机股票信息(新三板)
String[] xsbStock = RandomSource.financialSource().randomXsbStock();
String xsbStockName = xsbStock[0];
String xsbStockCode = xsbStock[1];
System.out.println("xsbStockName = " + xsbStockName + " -> xsbStockCode = " + xsbStockCode);
// 随机股票信息(北交所)
String[] bseStock = RandomSource.financialSource().randomBseStock();
String bseStockName = bseStock[0];
String bseStockCode = bseStock[1];
System.out.println("bseStockName = " + bseStockName + " -> bseStockCode = " + bseStockCode);
// 随机股票代码(纳斯达克)
String nasdaqStock = RandomSource.financialSource().randomNasdaqStock();
System.out.println("nasdaqStock = " + nasdaqStock);
String[] fund = RandomSource.financialSource().randomFund();
String fundName = fund[0];
System.out.println("fundName = " + fundName);
String fundCode = fund[1];
System.out.println("fundCode = " + fundCode);
// 随机生成20210201~20210228日期范围内的K线数据,起始价格为100,单日最大涨幅10%,单日最大跌幅-10%
List<KChartData> kList = RandomSource.financialSource().randomDailyKChartData(100, 0.1, -0.1, "20210201", "20210228");
// 随机获取一种货币信息
CurrencyInfo currencyInfo = RandomSource.financialSource().randomCurrencyInfo();
System.out.println("currencyInfo = " + currencyInfo);
// 英超
String footballTeam = RandomSource.sportSource().randomFootballTeam(CompetitionType.PREMIER_LEAGUE);
System.out.println("footballTeam = " + footballTeam);
// 西甲
String footballTeam1 = RandomSource.sportSource().randomFootballTeam(CompetitionType.LA_LIGA);
System.out.println("footballTeam1 = " + footballTeam1);
// 德甲
String footballTeam2 = RandomSource.sportSource().randomFootballTeam(CompetitionType.BUNDESLIGA);
System.out.println("footballTeam2 = " + footballTeam2);
// 意甲
String footballTeam3 = RandomSource.sportSource().randomFootballTeam(CompetitionType.SERIE_A);
System.out.println("footballTeam3 = " + footballTeam3);
// 法甲
String footballTeam4 = RandomSource.sportSource().randomFootballTeam(CompetitionType.LIGUE_1);
System.out.println("footballTeam4 = " + footballTeam4);
// 荷甲
String footballTeam5 = RandomSource.sportSource().randomFootballTeam(CompetitionType.EREDIVISIE);
System.out.println("footballTeam5 = " + footballTeam5);
// CBA
String basketballTeam = RandomSource.sportSource().randomBasketballTeam(CompetitionType.CBA);
System.out.println("basketballTeam = " + basketballTeam);
// NBA
String basketballTeam2 = RandomSource.sportSource().randomBasketballTeam(CompetitionType.NBA);
System.out.println("basketballTeam2 = " + basketballTeam2);
// (亚洲足联范围内)随机足球队名称
FootballTeam randomFootballTeam = RandomSource.sportSource().randomFootballTeam(FootballConfederation.AFC);
System.out.println("randomFootballTeam = " + randomFootballTeam);
// (欧洲足联范围内)随机足球队名称
FootballTeam randomFootballTeam2 = RandomSource.sportSource().randomFootballTeam(FootballConfederation.UEFA);
System.out.println("randomFootballTeam2 = " + randomFootballTeam2);
// 随机足球队名称(不限足球联合会)
FootballTeam randomFootballTeam3 = RandomSource.sportSource().randomFootballTeam();
System.out.println("randomFootballTeam3 = " + randomFootballTeam3);
String randomMobileModel = RandomSource.otherSource().randomMobileModel();
System.out.println("randomMobileModel = " + randomMobileModel);
此工具类支持自定义生成符合业务需求的随机数据,示例如下:
//准备字段定义
//字段name:随机姓名
DataField df1 = new DataField("name", () -> RandomSource.personInfoSource().randomChineseName());
//字段birthDate:随机日期
DataField df2 = new DataField("birthDate", () -> RandomSource.dateTimeSource().randomPastDate("yyyy-MM-dd"));
//字段salary:随机数字
DataField df3 = new DataField("salary", () -> RandomSource.numberSource().randomInt(5000, 18000));
List<DataField> fieldList = Lists.newArrayList(df1, df2, df3);
//设置数量
int total = 10;
//生成JSON
String json = DataUtils.generateJson(fieldList, total);
//生成CSV
String csv = DataUtils.generateCsv(fieldList, total);
//生成SQL之前先要指定表名
String tableName = "user";
//生成SQL插入语句
String sql = DataUtils.generateJson(fieldList, tableName, total);
详见:Github:Java随机数据生成器