大家好,我是开源君。
明天给大家分享的是【随机数据生成器】
我的项目介绍
这是一款简略易用的随机数据生成器。个别用于开发和测试阶段的数据填充、模仿、仿真钻研、演示等场景。能够集成到各种类型的java我的项目中应用。
长处
- 十分轻量级(不到1M),容易集成,无需过多第三方依赖
- 简略不便,无需编写冗余代码
- 生成的随机数据比拟靠近实在数据
疾速开始
<dependency>
<groupId>com.apifan.common</groupId>
<artifactId>common-random</artifactId>
<version>1.0.7</version>
</dependency>
随机数字
//生成1个1~101(不含)之间的随机整数
int a = NumberSource.getInstance().randomInt(1, 101);
//生成8个1~101(不含)之间的随机整数
int[] b = NumberSource.getInstance().randomInt(1, 101, 8);
//生成1个10000000000~20000000001(不含)之间的随机长整数
long c = NumberSource.getInstance().randomLong(10000000000L, 20000000001L);
随机汉字
//生成1个随机汉字
String i = OtherSource.getInstance().randomChinese();
//生成4个随机汉字
String j = OtherSource.getInstance().randomChinese(4);
随机中文名
//生成1个随机中文人名(性别随机)
String k = PersonInfoSource.getInstance().randomChineseName();
//生成1个随机男性中文人名
String k2 = PersonInfoSource.getInstance().randomMaleChineseName();
//生成1个随机女性中文人名
String k3 = PersonInfoSource.getInstance().randomFemaleChineseName();
英文名
//生成1个随机英文人名
String l = PersonInfoSource.getInstance().randomEnglishName();
生成姓名头像
- 该性能能够依据用户姓名疾速生成各类网站、app的用户头像
- 背景色彩随机,数据源取自最近十几年来广受欢迎的色彩,详情参见: Colors of the Year
- 反对应用自定义TTF字体,然而须要使用者自行保障字体版权非法以防止纠纷
- 该性能不反对在Android运行环境中应用(因为短少awt)
//姓名
String name = PersonInfoSource.getInstance().randomChineseName();
//头像文件保留门路
String targetPath = "/home/user/picture/" + name + ".png;
//应用默认的Dialog字体
PersonInfoSource.getInstance().generateNamePicture(name, targetPath);
//应用自定义的字体
String font = "/home/user/font/SourceHanSansCN-Normal.ttf";
PersonInfoSource.getInstance().generateNamePicture(name, targetPath, font);
随机生成合乎规定的虚构身份证号码
//生成1个随机的虚构身份证号码,地区为河北省,女性,出生日期在2001年1月11日至2008年2月22日之间
LocalDate beginDate2 = LocalDate.of(2001,1,11);
LocalDate endDate2 = LocalDate.of(2008,2,22);
String id2 = PersonInfoSource.getInstance().randomFemaleIdCard("河北省", beginDate2, endDate2);
随机车牌号
//生成1个随机中国大陆车牌号(新能源车型)
String n1 = OtherSource.getInstance().randomPlateNumber(true);
//生成1个随机中国大陆车牌号(非新能源车型)
String n2 = OtherSource.getInstance().randomPlateNumber();
随机地址
//随机获取省份
String prv = AreaSource.getInstance().randomProvince();
//随机获取城市(省份+城市,以逗号为分隔符)
String city = AreaSource.getInstance().randomCity(",");
//随机获取邮编
String zipCode = AreaSource.getInstance().randomZipCode();
//生成1个随机中国大陆具体地址
String addr = AreaSource.getInstance().randomAddress();
随机教育信息
//随机获取学历
String degree = EducationSource.getInstance().randomDegree();
//随机获取本科高校名称
String college = EducationSource.getInstance().randomCollege();
//随机获取小学名称
String primarySchoolName = EducationSource.getInstance().randomPrimarySchoolName();
//随机获取小学年级
String primarySchoolGrade = EducationSource.getInstance().randomPrimarySchoolGrade();
//随机获取中学名称
String highSchoolName = EducationSource.getInstance().randomHighSchoolName();
//随机获取中学年级
String highSchoolGrade = EducationSource.getInstance().randomHighSchoolGrade();
//随机班级名称
String className = EducationSource.getInstance().randomClassName();
反对的随机类型比拟多,这里就不一一列出了。次要包含但不限于以下畛域。
-
日期工夫
- 天文
- 互联网
- 个人信息
- 教育
- 金融
- 体育
- 其余
注意事项
- 随机数据由程序随机生成,不存在真实性,但有可能与实在数据雷同(纯属巧合)。
- 程序中应用了小局部实在数据(包含但不限于:行政区划名称、邮编、区号、高校名称、股票代码及名称等)作为根底数据源,全副来自于各个非法经营的网站上的可公开拜访的网页;其中波及的著作权或商标的所有权属于各自非法的拥有者。
我的项目地址
https://www.github.com/shaoxi…
最初
依旧安利一波咱们的公众号:【开掘开源的价值】
继续分享一些好玩,乏味,又沙雕的开源我的项目或者优质的开发工具,实用的编程技巧,欢送关注!
历史推送:
- Java高效解决Excel【阿里yyds!】
- 腾讯开源的ORM库
- 盘点8月份yyds的开源我的项目!
- 前后端拆散的在线考试零碎
点赞,再看,转发呐!
发表回复