{"id":13694647,"url":"https://github.com/yindz/common-random","last_synced_at":"2026-01-14T03:35:09.261Z","repository":{"id":37676665,"uuid":"234715610","full_name":"yindz/common-random","owner":"yindz","description":"简单易用的随机数据生成器。生成各种比较真实的假数据。一般用于开发和测试阶段的数据填充模拟。支持各类中国特色本地化的数据格式。An easy-to use random data generator. Generally used for data filling, simulation, demonstration and other scenarios in the development and test phase.","archived":false,"fork":false,"pushed_at":"2024-11-20T05:18:08.000Z","size":1682,"stargazers_count":642,"open_issues_count":0,"forks_count":127,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-07-06T17:50:09.122Z","etag":null,"topics":["fake-data","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yindz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-18T10:09:48.000Z","updated_at":"2025-06-30T05:55:58.000Z","dependencies_parsed_at":"2025-05-03T04:30:50.634Z","dependency_job_id":"0fc3c716-d315-4cf4-a2fa-942a958272fe","html_url":"https://github.com/yindz/common-random","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/yindz/common-random","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yindz%2Fcommon-random","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yindz%2Fcommon-random/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yindz%2Fcommon-random/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yindz%2Fcommon-random/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yindz","download_url":"https://codeload.github.com/yindz/common-random/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yindz%2Fcommon-random/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T01:52:23.358Z","status":"online","status_checked_at":"2026-01-14T02:00:06.678Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fake-data","java"],"created_at":"2024-08-02T17:01:36.417Z","updated_at":"2026-01-14T03:35:09.241Z","avatar_url":"https://github.com/yindz.png","language":"Java","readme":"![https://opensource.org/licenses/Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)\r\n![](https://img.shields.io/badge/java-1.8%2B-yellow)\r\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.yindz/common-random/badge.svg \"Maven Central\")](https://mvnrepository.com/artifact/io.github.yindz/common-random)\r\n# 随机数据生成器\r\n## 概述\r\n简单易用的随机数据生成器。一般用于开发和测试阶段的数据填充、模拟、仿真研究、演示等场景。可以集成到各种类型的java项目中使用。\r\n\r\n## 优点\r\n- 非常轻量级(~~不到1M~~ *由于基础数据增加，体积已达到1.2M*)，容易集成，无需过多第三方依赖\r\n- 简单方便，无需编写冗余代码\r\n- 生成的随机数据比较接近真实数据\r\n\r\n## 快速开始\r\n- [如何使用](#如何使用)\r\n- [支持哪些随机数据类型](#支持的随机数据类型)\r\n- [JSON库的相关说明](#JSON库说明)\r\n- [拼音库的相关说明](#拼音库说明)\r\n- [常见问题](#常见问题)\r\n- [注意事项](#注意事项)\r\n- [最近版本历史](#版本历史)\r\n\r\n## 支持的随机数据类型\r\n\r\n### 日期时间\r\n- [随机日期](#随机日期)\r\n- [随机时间](#随机时间)\r\n- [随机时间戳](#随机时间戳)\r\n- [随机时区名称](#随机时区名称)\r\n\r\n### 地理\r\n- [随机省份和城市](#随机地址)\r\n- [随机国家或地区（基于ISO 3166-1标准）](#随机国家或地区)\r\n- [虚拟经纬度](#随机经纬度)\r\n- [随机邮编](#随机地址)\r\n- [虚拟联系地址](#随机地址)\r\n- [随机固话区号](#随机固话)\r\n- [虚拟固话号码](#随机固话)\r\n\r\n### 互联网\r\n- [虚拟邮箱地址](#随机邮箱地址)\r\n- [虚拟域名](#随机域名)\r\n- [虚拟静态URL](#随机静态url)\r\n- [虚拟IPv4地址](#随机ipv4地址)\r\n- [虚拟IPv6地址](#随机ipv6地址)\r\n- [虚拟网卡MAC地址](#随机网卡mac地址)\r\n- [随机强密码](#随机强密码)\r\n- [随机User-Agent](#随机useragent)\r\n- [随机端口号](#随机端口号)\r\n- [虚拟app名称](#随机app信息)\r\n- [虚拟app bundle id](#随机app信息)\r\n- [虚拟app版本号](#随机app信息)\r\n\r\n### 个人信息\r\n- [虚拟中文人名](#中文名)\r\n- [虚拟英文人名](#英文名)\r\n- [虚拟身份证号码](#随机生成符合规则的虚拟身份证号码)\r\n- [虚拟网络昵称](#随机网络昵称)\r\n- [虚拟拼音网络昵称](#随机网络昵称)\r\n- [虚拟手机号码](#随机中国大陆手机号)\r\n- [虚拟QQ号码](#随机qq信息)\r\n- [虚拟非主流QQ网名](#随机qq信息)\r\n- [随机民族名称](#随机民族名称)\r\n\r\n### 教育\r\n- [随机学历](#随机教育背景信息)\r\n- [虚拟小学名称、年级、班级](#随机教育背景信息)\r\n- [虚拟中学名称、年级、班级](#随机教育背景信息)\r\n- [随机高校及专业名称](#随机教育背景信息)\r\n\r\n### 金融\r\n- [随机股票名称+股票代码](#股票名称和股票代码)\r\n- [虚拟日K线数据](#日k线数据)\r\n- [随机开放式基金名称+基金代码](#开放式基金名称和基金代码)\r\n- [随机货币信息](#货币)\r\n- [虚拟银行卡（借记卡及信用卡）号码](#随机虚拟银行卡号码)\r\n\r\n### 体育\r\n- [随机六大足球联赛球队名称](#足球联赛球队名称)\r\n- [随机篮球联赛球队名称](#篮球联赛球队名称)\r\n- [随机国家及地区的足球代表队名称](#国家及地区的足球代表队)\r\n\r\n### 其它\r\n- [随机数字](#随机数字)\r\n- [随机汉字](#随机汉字)\r\n- [随机成语](#随机成语)\r\n- [随机唐诗](#随机唐诗)\r\n- [虚拟车牌号](#随机中国大陆车牌号)\r\n- [随机热门手机型号](#热门手机型号)\r\n- [随机RGB颜色值](#随机颜色值)\r\n- [随机HEX颜色值](#随机颜色值)\r\n- [随机中文短句](#随机中文短句)\r\n- [随机英文文本](#随机英文文本)\r\n- [虚拟企业及部门名称](#随机公司及部门名称)\r\n- [随机营销号文案](#随机营销号)\r\n- [随机ISBN](#随机EAN)\r\n- [随机EAN商品编码](#随机EAN)\r\n- [随机行业分类](#随机行业分类)\r\n- [随机统一社会信用代码](#统一社会信用代码)\r\n- [数据生成工具](#数据生成工具)\r\n\r\n## 如何使用\r\n### Java版本要求\r\n1.8或更高\r\n\r\n### 配置依赖\r\n最新`1.1.x`版本已发布中央仓库（请注意groupId已经变了）：\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003eio.github.yindz\u003c/groupId\u003e\r\n    \u003cartifactId\u003ecommon-random\u003c/artifactId\u003e\r\n    \u003cversion\u003e1.1.0\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n`1.0.x`旧版本：\r\n\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003ecom.apifan.random\u003c/groupId\u003e\r\n    \u003cartifactId\u003ecommon-random\u003c/artifactId\u003e\r\n    \u003cversion\u003e1.0.21\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n### 基础用法\r\n#### 统一入口\r\n```\r\n//地区类虚拟数据\r\nAreaSource areaSource = RandomSource.areaSource();\r\n\r\n//日期时间类虚拟数据\r\nDateTimeSource dateTimeSource = RandomSource.dateTimeSource();\r\n\r\n//教育类虚拟数据\r\nEducationSource educationSource = RandomSource.educationSource();\r\n\r\n//金融类虚拟数据\r\nFinancialSource financialSource = RandomSource.financialSource();\r\n\r\n//互联网信息类虚拟数据\r\nInternetSource internetSource = RandomSource.internetSource();\r\n\r\n//数字类虚拟数据\r\nNumberSource numberSource = RandomSource.numberSource();\r\n\r\n//个人类虚拟数据\r\nPersonInfoSource personInfoSource = RandomSource.personInfoSource();\r\n\r\n//体育竞技类虚拟数据\r\nSportSource sportSource = RandomSource.sportSource();\r\n\r\n//语言文字类虚拟数据\r\nLanguageSource languageSource = RandomSource.languageSource();\r\n\r\n//其它杂项虚拟数据\r\nOtherSource otherSource = RandomSource.otherSource();\r\n```\r\n\r\n#### 随机数字\r\n```\r\n//生成1个1~101(不含)之间的随机整数\r\nint a = RandomSource.numberSource().randomInt(1, 101);\r\n\r\n//生成8个1~101(不含)之间的随机整数\r\nint[] b = RandomSource.numberSource().randomInt(1, 101, 8);\r\n\r\n//生成1个10000000000~20000000001(不含)之间的随机长整数\r\nlong c = RandomSource.numberSource().randomLong(10000000000L, 20000000001L);\r\n\r\n//生成9个10000000000~20000000001(不含)之间的随机长整数\r\nlong[] d = RandomSource.numberSource().randomLong(10000000000L, 20000000001L, 9);\r\n\r\n//生成1个0.01~0.51(不含)之间的随机整数\r\ndouble e = RandomSource.numberSource().randomDouble(0.01D, 0.51D);\r\n\r\n//生成8个0.01~0.51(不含)之间的随机整数\r\ndouble[] f = RandomSource.numberSource().randomDouble(0.01D, 0.51D, 8);\r\n\r\n//生成随机百分比\r\nBigDecimal percent = RandomSource.numberSource().randomPercent();\r\n```\r\n#### 随机汉字\r\n```\r\n//生成1个随机汉字\r\nRandomSource.languageSource().randomChinese();\r\n\r\n//生成4个随机汉字\r\nRandomSource.languageSource().randomChinese(4);\r\n```\r\n#### 随机成语\r\n```\r\nRandomSource.languageSource().randomChineseIdiom();\r\n```\r\n#### 随机唐诗\r\n```\r\nRandomSource.languageSource().randomTangPoem();\r\n```\r\n#### 随机人名\r\n##### 中文名\r\n```\r\n//生成1个随机中文人名(性别随机)\r\nRandomSource.personInfoSource().randomChineseName();\r\n\r\n//生成1个随机男性中文人名\r\nRandomSource.personInfoSource().randomMaleChineseName();\r\n\r\n//生成1个随机女性中文人名\r\nRandomSource.personInfoSource().randomFemaleChineseName();\r\n```\r\n##### 英文名\r\n```\r\n//生成1个随机英文人名\r\nRandomSource.personInfoSource().randomEnglishName();\r\n```\r\n\r\n#### 随机生成符合规则的虚拟身份证号码\r\n```\r\n//生成1个随机的虚拟身份证号码，地区为广西壮族自治区，男性，出生日期在1990年11月11日至1999年12月12日之间\r\nLocalDate beginDate = LocalDate.of(1990,11,11);\r\nLocalDate endDate = LocalDate.of(1999,12,12); \r\nString id1 = RandomSource.personInfoSource().randomMaleIdCard(Province.GX, beginDate, endDate);\r\n\r\n//生成1个随机的虚拟身份证号码，地区为河北省，女性，出生日期在2001年1月11日至2008年2月22日之间\r\nLocalDate beginDate2 = LocalDate.of(2001,1,11);\r\nLocalDate endDate2 = LocalDate.of(2008,2,22);\r\nString id2 = RandomSource.personInfoSource().randomFemaleIdCard(Province.HE, beginDate2, endDate2);\r\n\r\n//生成1个随机的虚拟身份证号码，地区为广西壮族自治区，男性，年龄为18岁\r\nString id3 = RandomSource.personInfoSource().randomMaleIdCard(Province.GX, 18);\r\n\r\n//生成1个随机的虚拟身份证号码，地区为河北省，女性，年龄为19岁\r\nString id4 = RandomSource.personInfoSource().randomFemaleIdCard(Province.HE, 19);\r\n```\r\n注意：\r\n- 身份证号码前6位地区码数据取自[民政部网站2019年公开数据](http://www.mca.gov.cn/article/sj/xzqh/2019/)\r\n- 随机生成的虚拟身份证号码符合校验规则，但有可能与真实号码相同（纯属巧合）\r\n\r\n#### 随机虚拟银行卡号码\r\n```\r\n//生成1个随机虚拟VISA信用卡号码\r\nString cc1 = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.Visa);\r\n\r\n//生成1个随机虚拟MasterCard信用卡号码\r\nString cc2 = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.MasterCard);\r\n\r\n//生成1个随机虚拟American Express信用卡号码\r\nString cc3 = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.Amex);\r\n\r\n//生成1个随机虚拟银联信用卡号码\r\nString cc4 = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.UnionPay);\r\n\r\n//生成1个随机虚拟JCB信用卡号码\r\nString cc5 = RandomSource.personInfoSource().randomCreditCardNo(CreditCardType.JCB);\r\n\r\n//生成1个随机虚拟借记卡(储蓄卡)号码\r\nString dbc = RandomSource.personInfoSource().randomDebitCardNo();\r\n```\r\n注意：\r\n- 随机生成的虚拟银行卡号码只是前缀和位数符合规则，不会与现实中的真实卡号产生重合，无法用于支付，仅供模拟测试/仿真/项目演示等用途\r\n\r\n#### 随机中国大陆手机号\r\n```\r\n//生成1个随机中国大陆手机号\r\nRandomSource.personInfoSource().randomChineseMobile();\r\n```\r\n#### 随机邮箱地址\r\n```\r\n//生成1个随机邮箱地址，后缀随机，邮箱用户名最大长度为10\r\nRandomSource.internetSource().randomEmail(10);\r\n\r\n//生成1个随机邮箱地址，后缀为163.com，邮箱用户名最大长度为10\r\nRandomSource.internetSource().randomEmail(10, \"163.com\");\r\n```\r\n#### 随机域名\r\n```\r\n//生成1个随机域名，域名最大长度为16\r\nRandomSource.internetSource().randomDomain(16);\r\n```\r\n#### 随机ipv4地址\r\n```\r\n//生成1个随机公网IPv4地址\r\nString pub = RandomSource.internetSource().randomPublicIpv4();\r\n\r\n//生成1个随机私有(内网)IPv4地址\r\nString prv = RandomSource.internetSource().randomPrivateIpv4();\r\n```\r\n#### 随机ipv6地址\r\n```\r\n//生成1个随机ipv6地址\r\nString ipv6 = RandomSource.internetSource().randomIpV6();\r\n```\r\n#### 随机端口号\r\n```\r\n//生成1个随机端口号\r\nRandomSource.internetSource().randomPort();\r\n```\r\n#### 随机app信息\r\n```\r\n//生成1个随机App名称\r\nString appName = RandomSource.internetSource().randomAppName();\r\n\r\n//生成1个随机App Bundle ID\r\nString appBundleID = RandomSource.internetSource().randomAppBundleId();\r\n\r\n//生成1个随机App版本号\r\nString appVersionCode = RandomSource.internetSource().randomAppVersionCode();\r\n```\r\n#### 随机静态url\r\n```\r\n//生成1个随机静态url，后缀为jpg\r\nString url = RandomSource.internetSource().randomStaticUrl(\"jpg\");\r\n```\r\n#### 随机日期\r\n```\r\n//生成1个2020年的随机日期，日期格式为yyyy-MM-dd\r\nString d1 = RandomSource.dateTimeSource().randomDate(2020, \"yyyy-MM-dd\");\r\n\r\n//生成1个2020年1月2日之后的随机日期，日期格式为yyyy-MM-dd\r\nString d2 = RandomSource.dateTimeSource().randomFutureDate(LocalDate.of(2020,1,2), \"yyyy-MM-dd\");\r\n\r\n//生成1个今天(基于系统时间判断)之后的随机日期，日期格式为yyyy-MM-dd\r\nString d3 = RandomSource.dateTimeSource().randomFutureDate(\"yyyy-MM-dd\");\r\n\r\n//生成1个2020年1月2日之前1年内的随机日期，日期格式为yyyy-MM-dd\r\nString d4 = RandomSource.dateTimeSource().randomPastDate(LocalDate.of(2020,1,2), \"yyyy-MM-dd\");\r\n\r\n//生成1个今天(基于系统时间判断)之前1年内的随机日期，日期格式为yyyy-MM-dd\r\nString d5 = RandomSource.dateTimeSource().randomPastDate(\"yyyy-MM-dd\");\r\n\r\n//生成1个2020年1月2日之前10年内的随机日期，日期格式为yyyy-MM-dd\r\nString dd = RandomSource.dateTimeSource().randomPastDate(LocalDate.of(2020,1,2), 3650, \"yyyy-MM-dd\");\r\n\r\n//生成1个2000年1月11日至2010年2月22日范围之间的随机日期，日期格式为yyyy-MM-dd\r\nLocalDate beginDate = LocalDate.of(2000,1,11);\r\nLocalDate endDate = LocalDate.of(2010,2,22);\r\nString d6 = RandomSource.dateTimeSource().randomDate(beginDate, endDate, \"yyyy-MM-dd\");\r\n```\r\n#### 随机时间\r\n```\r\n//生成过去7天范围内的随机时间\r\nLocalDateTime time1 = RandomSource.dateTimeSource().randomPastTime(7);\r\n\r\n//生成未来7天范围内的随机时间\r\nLocalDateTime time2 = RandomSource.dateTimeSource().randomFutureTime(7);\r\n\r\n//生成2020年2月14日当天范围内的随机时间\r\nLocalDateTime time3 = RandomSource.dateTimeSource().randomTime(2020, 2, 14);\r\n\r\n//生成过去100秒范围内的随机时间\r\nLocalDateTime time4 = RandomSource.dateTimeSource().randomPastTime(LocalDateTime.now(), 100);\r\n\r\n//生成未来100秒范围内的随机时间\r\nLocalDateTime time5 = RandomSource.dateTimeSource().randomFutureTime(LocalDateTime.now(), 100);\r\n```\r\n#### 随机时间戳\r\n```\r\n//生成1个当天范围内的随机时间戳\r\nlong ts1 = RandomSource.dateTimeSource().randomTimestamp(LocalDate.now());\r\n\r\n//生成1个2020年3月6日范围内的随机时间戳\r\nlong ts2 = RandomSource.dateTimeSource().randomTimestamp(LocalDate.of(2020, 3, 6));\r\n\r\n//生成1个介于2020年3月6日12:00:00至2020年3月6日12:30:00之间的随机时间戳\r\nLocalDateTime begin = LocalDateTime.of(2020, 3, 6, 12, 0, 0);\r\nLocalDateTime end = LocalDateTime.of(2020, 3, 6, 12, 30, 0);\r\nlong ts3 = RandomSource.dateTimeSource().randomTimestamp(begin, end);\r\n\r\n//生成1个2020年3月6日12:00:00之后180秒内的随机时间戳\r\nLocalDateTime base1 = LocalDateTime.of(2020, 3, 6, 12, 0, 0);\r\nlong ts4 = RandomSource.dateTimeSource().randomFutureTimestamp(base1, 180);\r\n\r\n//生成1个2020年3月7日13:00:00之前120秒内的随机时间戳\r\nLocalDateTime base2 = LocalDateTime.of(2020, 3, 7, 13, 0, 0);\r\nlong ts5 = RandomSource.dateTimeSource().randomPastTimestamp(base2, 120);\r\n```\r\n#### 随机时区名称\r\n```\r\n//生成1个随机时区名称\r\nString timezone = RandomSource.dateTimeSource().randomTimezoneName();\r\n```\r\n\r\n#### 随机强密码\r\n```\r\n//生成1个随机强密码，长度为16，无特殊字符\r\nRandomSource.personInfoSource().randomStrongPassword(16, false);\r\n\r\n//生成1个随机强密码，长度为16，有特殊字符\r\nRandomSource.personInfoSource().randomStrongPassword(16, true);\r\n```\r\n\r\n#### 随机地址\r\n```\r\n//随机获取省份\r\nRandomSource.areaSource().randomProvince();\r\n\r\n//随机获取城市(省份+城市，以逗号为分隔符)\r\nRandomSource.areaSource().randomCity(\",\");\r\n\r\n//随机获取邮编\r\nRandomSource.areaSource().randomZipCode();\r\n\r\n//生成1个随机中国大陆详细地址\r\nRandomSource.areaSource().randomAddress();\r\n```\r\n\r\n#### 随机国家或地区\r\n```\r\n//随机获取1个编码首字母为b的国家或地区\r\nRandomSource.areaSource().randomCountryOrRegionCode(\"b\");\r\n\r\n//随机获取1个国家或地区(不限首字母)\r\nRandomSource.areaSource().randomCountryOrRegionCode();\r\n```\r\n\r\n#### 随机经纬度\r\n```\r\n//随机生成1个纬度\r\ndouble lat = RandomSource.areaSource().randomLatitude();\r\n\r\n//随机生成1个经度\r\ndouble lng = RandomSource.areaSource().randomLongitude();\r\n```\r\n\r\n#### 随机固话\r\n```\r\n//随机固话区号(省级行政区名称不需要包含后缀)\r\nRandomSource.areaSource().randomPhoneCode(\"湖南\");\r\n\r\n//随机固话号码(使用-作为分隔符，默认的分隔符是空格)\r\nRandomSource.areaSource().randomPhoneNumber(\"广东\", \"-\");\r\n```\r\n\r\n#### 随机中国大陆车牌号\r\n```\r\n//生成1个随机中国大陆车牌号(新能源车型)\r\nRandomSource.otherSource().randomPlateNumber(true);\r\n\r\n//生成1个随机中国大陆车牌号(非新能源车型)\r\nRandomSource.otherSource().randomPlateNumber();\r\n```\r\n#### 随机网络昵称\r\n```\r\n//生成1个随机英文网络昵称，最大长度为8个字符\r\nRandomSource.personInfoSource().randomNickName(8);\r\n\r\n//生成1个随机汉字网络昵称，最大长度为8个汉字\r\nRandomSource.personInfoSource().randomChineseNickName(8);\r\n\r\n//基于随机汉字网络昵称生成1个拼音网络昵称，最大长度为4个汉字\r\nRandomSource.personInfoSource().randomPinyinNickName(4);\r\n```\r\n#### 随机qq信息\r\n```\r\n//生成1个随机QQ号\r\nRandomSource.personInfoSource().randomQQAccount();\r\n\r\n//生成1个随机非主流QQ网名\r\nRandomSource.personInfoSource().randomQQNickName();\r\n```\r\n\r\n#### 随机民族名称\r\n```\r\nRandomSource.otherSource().randomEthnicName();\r\n```\r\n\r\n#### 随机教育背景信息\r\n```\r\n//随机获取学历\r\nRandomSource.educationSource().randomDegree();\r\n\r\n//随机获取本科高校名称\r\nRandomSource.educationSource().randomCollege();\r\n\r\n//随机高校专业名称\r\nRandomSource.educationSource().randomMajorName();\r\n\r\n//随机获取小学名称\r\nRandomSource.educationSource().randomPrimarySchoolName();\r\n\r\n//随机获取小学年级\r\nRandomSource.educationSource().randomPrimarySchoolGrade();\r\n\r\n//随机获取中学名称\r\nRandomSource.educationSource().randomHighSchoolName();\r\n\r\n//随机获取中学年级\r\nRandomSource.educationSource().randomHighSchoolGrade();\r\n\r\n//随机班级名称\r\nRandomSource.educationSource().randomClassName();\r\n```\r\n#### 随机公司及部门名称\r\n```\r\n//随机生成1个公司名称，地区前缀为北京\r\nRandomSource.otherSource().randomCompanyName(\"北京\");\r\n\r\n//随机生成1个公司部门名称\r\nRandomSource.otherSource().randomCompanyDepartment();\r\n```\r\n\r\n#### 随机中文短句\r\n```\r\n//随机生成1条中文短句\r\nRandomSource.languageSource().randomChineseSentence();\r\n```\r\n\r\n#### 随机英文文本\r\n```\r\n//随机生成1条英文文本，包含10个单词\r\nRandomSource.languageSource().randomEnglishText(10);\r\n```\r\n\r\n#### 随机营销号\r\n```\r\nRandomSource.languageSource().randomNonsenseTitle(\"星期一\", \"下雨\");\r\n```\r\n\r\n```\r\nRandomSource.languageSource().randomNonsense(\"星期一\", \"下雨\");\r\n```\r\n\r\n#### 随机行业分类\r\n```\r\nRandomSource.otherSource().randomEconomicCategory();\r\n```\r\n说明：行业分类编码和名称来自国家统计局发布的公开数据\r\n\r\n#### 统一社会信用代码\r\n```\r\nRandomSource.otherSource().randomSocialCreditCode();\r\n```\r\n\r\n#### 随机EAN\r\n```\r\n//随机ISBN，返回结果需要分隔符-，格式例如：978-7-XXXX-XXXX-X\r\nRandomSource.otherSource().randomISBN(true);\r\n\r\n//随机ISBN，返回结果不需要分隔符，格式例如：9787XXXXXXXXX\r\nRandomSource.otherSource().randomISBN(false);\r\n\r\n//随机国际商品编码，格式例如：691XXXXXXXXXX\r\nRandomSource.otherSource().randomEAN();\r\n```\r\n说明：\r\n- 本程序随机生成的EAN编码长度为13位\r\n- 本程序随机生成的EAN编码符合标准校验规则，仅供模拟测试/仿真/项目演示等用途，并不表示现实中真实存在该编码对应的商品（如有雷同纯属巧合）\r\n\r\n#### 随机useragent\r\n```\r\n//随机生成1个PC User-Agent\r\nRandomSource.internetSource().randomPCUserAgent();\r\n\r\n//随机生成1个Android User-Agent\r\nRandomSource.internetSource().randomAndroidUserAgent();\r\n\r\n//随机生成1个iOS User-Agent\r\nRandomSource.internetSource().randomIOSUserAgent();\r\n```\r\n#### 随机网卡mac地址\r\n```\r\n//随机生成1个网卡MAC地址，使用:作为分隔符\r\nRandomSource.internetSource().randomMacAddress(\":\");\r\n```\r\n#### 随机颜色值\r\n```\r\n//随机生成1个RGB颜色值\r\nint[] rgb = RandomSource.otherSource().randomRgbColor();\r\n\r\n//随机生成1个16进制(HEX)颜色值\r\nString hex = RandomSource.otherSource().randomHexColor();\r\n```\r\n#### 股票名称和股票代码\r\n```\r\n//随机股票信息(沪A+深A+创业板+科创版)\r\nString[] stock = RandomSource.financialSource().randomStock();\r\nString stockName = stock[0];\r\nString stockCode = stock[1];\r\n\r\n//随机股票信息(港股)\r\nString[] hkStock = RandomSource.financialSource().randomHKStock();\r\nString hkStockName = hkStock[0];\r\nString hkStockCode = hkStock[1];\r\n\r\n//随机股票信息(新三板)\r\nString[] xsbStock = RandomSource.financialSource().randomXsbStock();\r\nString xsbStockName = xsbStock[0];\r\nString xsbStockCode = xsbStock[1];\r\n\r\n//随机股票信息(北交所)\r\nString[] bseStock = RandomSource.financialSource().randomBseStock();\r\nString bseStockName = bseStock[0];\r\nString bseStockCode = bseStock[1];\r\n\r\n//随机股票代码(纳斯达克)\r\nRandomSource.financialSource().randomNasdaqStock();\r\n```\r\n#### 开放式基金名称和基金代码\r\n```\r\nString[] fund = RandomSource.financialSource().randomFund();\r\nString fundName = fund[0];\r\nString fundCode = fund[1];\r\n```\r\n#### 日k线数据\r\n```\r\n//随机生成20210201~20210228日期范围内的K线数据，起始价格为100，单日最大涨幅10%，单日最大跌幅-10%\r\nList\u003cKChartData\u003e kList = RandomSource.financialSource().randomDailyKChartData(100, 0.1, -0.1, \"20210201\", \"20210228\");\r\n```\r\n#### 货币\r\n```\r\n//随机获取一种货币信息\r\nCurrencyInfo ci = RandomSource.financialSource().randomCurrencyInfo();\r\n```\r\n#### 足球联赛球队名称\r\n```\r\n//英超\r\nRandomSource.sportSource().randomFootballTeam(CompetitionType.PREMIER_LEAGUE);\r\n\r\n//西甲\r\nRandomSource.sportSource().randomFootballTeam(CompetitionType.LA_LIGA);\r\n\r\n//德甲\r\nRandomSource.sportSource().randomFootballTeam(CompetitionType.BUNDESLIGA);\r\n\r\n//意甲\r\nRandomSource.sportSource().randomFootballTeam(CompetitionType.SERIE_A);\r\n\r\n//法甲\r\nRandomSource.sportSource().randomFootballTeam(CompetitionType.LIGUE_1);\r\n\r\n//荷甲\r\nRandomSource.sportSource().randomFootballTeam(CompetitionType.EREDIVISIE);\r\n```\r\n#### 篮球联赛球队名称\r\n```\r\n//CBA\r\nRandomSource.sportSource().randomBasketballTeam(CompetitionType.CBA);\r\n\r\n//NBA\r\nRandomSource.sportSource().randomBasketballTeam(CompetitionType.NBA);\r\n```\r\n#### 国家及地区的足球代表队\r\n```\r\n//(亚洲足联范围内)随机足球队名称\r\nRandomSource.sportSource().randomFootballTeam(FootballConfederation.AFC);\r\n\r\n//(欧洲足联范围内)随机足球队名称\r\nRandomSource.sportSource().randomFootballTeam(FootballConfederation.UEFA);\r\n\r\n//随机足球队名称(不限足球联合会)\r\nRandomSource.sportSource().randomFootballTeam();\r\n```\r\n访问 [Wikipedia网页](https://en.wikipedia.org/wiki/Category:FIFA_confederations) 可以查看完整的足球联合会列表信息。\r\n\r\n#### 热门手机型号\r\n```\r\nRandomSource.otherSource().randomMobileModel();\r\n```\r\n\r\n## 数据生成工具\r\n此工具类支持自定义生成符合业务需求的随机数据，示例如下：\r\n```\r\n//准备字段定义\r\n//字段name：随机姓名\r\nDataField df1 = new DataField(\"name\", () -\u003e RandomSource.personInfoSource().randomChineseName());\r\n//字段birthDate：随机日期\r\nDataField df2 = new DataField(\"birthDate\", () -\u003e RandomSource.dateTimeSource().randomPastDate(\"yyyy-MM-dd\"));\r\n//字段salary：随机数字\r\nDataField df3 = new DataField(\"salary\", () -\u003e RandomSource.numberSource().randomInt(5000, 18000));\r\nList\u003cDataField\u003e fieldList = Lists.newArrayList(df1, df2, df3);\r\n\r\n//设置数量\r\nint total = 10;\r\n\r\n//生成JSON\r\nString json = DataUtils.generateJson(fieldList, total); \r\n\r\n//生成CSV \r\nString csv = DataUtils.generateCsv(fieldList, total); \r\n\r\n//生成SQL之前先要指定表名\r\nString tableName = \"user\";\r\n//生成SQL插入语句\r\nString sql = DataUtils.generateJson(fieldList, tableName, total);     \r\n```\r\n\r\n## JSON库说明\r\n### 主要变化\r\n考虑到某些项目可能使用其它JSON依赖库，**从 1.0.16 版起**，本程序就不再强依赖 jackson，更加灵活：\r\n- jackson（默认）\r\n- fastjson2\r\n- gson\r\n\r\n### 依赖坐标\r\n由于不再强依赖 jackson，因此您需要在您的项目中手动添加相关依赖。三选一：\r\n1. jackson\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003ecom.fasterxml.jackson.core\u003c/groupId\u003e\r\n    \u003cartifactId\u003ejackson-databind\u003c/artifactId\u003e\r\n    \u003cversion\u003e2.13.4\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n版本号仅供参考，最新版本请[查看这里](https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind)\r\n\r\n2. fastjson\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003ecom.alibaba.fastjson2\u003c/groupId\u003e\r\n    \u003cartifactId\u003efastjson2\u003c/artifactId\u003e\r\n    \u003cversion\u003e2.0.53\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n版本号仅供参考，最新版本请[查看这里](https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2)\r\n\r\n3. gson\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003ecom.google.code.gson\u003c/groupId\u003e\r\n    \u003cartifactId\u003egson\u003c/artifactId\u003e\r\n    \u003cversion\u003e2.9.1\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n版本号仅供参考，最新版本请[查看这里](https://mvnrepository.com/artifact/com.google.code.gson/gson)\r\n\r\n## 拼音库说明\r\n### 主要变化\r\n考虑到某些项目可能使用 pinyin4j，**从 1.0.16 版起**，本程序就不再强依赖 tinypinyin，更加灵活：\r\n- tinypinyin（默认）\r\n- pinyin4j\r\n\r\n### 如何设置\r\n由于不再强依赖 tinypinyin，因此您需要在您的项目中手动添加相关依赖。二选一：\r\n1. tinypinyin\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003eio.github.biezhi\u003c/groupId\u003e\r\n    \u003cartifactId\u003eTinyPinyin\u003c/artifactId\u003e\r\n    \u003cversion\u003e2.0.3.RELEASE\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n版本号仅供参考，最新版本请[查看这里](https://mvnrepository.com/artifact/io.github.biezhi/TinyPinyin)\r\n\r\n2. pinyin4j\r\n```xml\r\n\u003cdependency\u003e\r\n    \u003cgroupId\u003ecom.belerweb\u003c/groupId\u003e\r\n    \u003cartifactId\u003epinyin4j\u003c/artifactId\u003e\r\n    \u003cversion\u003e2.5.1\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n版本号仅供参考，最新版本请[查看这里](https://mvnrepository.com/artifact/com.belerweb/pinyin4j)\r\n\r\n## 常见问题\r\n| 报错信息                                                                                                                  | 原因及解决方法               |\r\n|-----------------------------------------------------------------------------------------------------------------------|-----------------------|\r\n| ```java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/JsonProcessingException```                              | 缺少jackson依赖，手动添加即可    |\r\n| ```java.lang.NoClassDefFoundError: com/alibaba/fastjson2/TypeReference```                                             | 缺少fastjson2依赖，手动添加即可  |\r\n| ```java.lang.NoClassDefFoundError: com/google/gson/reflect/TypeToken```                                               | 缺少gson依赖，手动添加即可       |\r\n| ```java.lang.NoClassDefFoundError: com/github/promeg/pinyinhelper/Pinyin```                                           | 缺少tinypinyin依赖，手动添加即可 |\r\n| ```java.lang.NoClassDefFoundError: net/sourceforge/pinyin4j/format/exception/BadHanyuPinyinOutputFormatCombination``` | 缺少pinyin4j依赖，手动添加即可   |\r\n\r\n## 版本历史\r\n### v1.1.0\r\n- 包名修改为`io.github.yindz`，类名保持不变\r\n- JSON库升级到`fastjson2`，不再支持`fastjson`\r\n- 支持日期转农历\r\n- 修订基础数据\r\n- `randomAddress(nextArea())`[修改为公开方法](https://github.com/yindz/common-random/issues/77)\r\n- 升级相关依赖\r\n\r\n### v1.0.21\r\n- 修订基础数据\r\n- 新增支持生成常见文件后缀\r\n- 支持生成虚构省市名称及地址\r\n- 逻辑优化\r\n\r\n### v1.0.20\r\n- 新增支持生成随机希腊字母\r\n- 完善逻辑\r\n\r\n### v1.0.19\r\n- 增加统一入口类RandomSource\r\n- 生成随机地址、身份证号、公司名称时可通过枚举指定省级行政区（避免因名称规范问题导致的错误）\r\n- 从杂项数据源中拆分出单独的语言文字数据源\r\n\r\n### v1.0.18\r\n- 增加纳斯达克上市股票信息\r\n\r\n### v1.0.17\r\n- 不再支持生成图片的功能\r\n- 更新一些基础数据\r\n\r\n### v1.0.16\r\n- 不再强依赖jackson，支持jackson/fastjson/gson三种不同的json库\r\n- 不再强依赖tinypinyin，支持tinypinyin/pinyin4j两种不同的拼音库\r\n\r\n### v1.0.15\r\n- 新增支持生成虚拟借记卡号;\r\n- 新增支持生成英文文本;\r\n- 新增支持生成虚拟统一社会信用代码;\r\n- 修订一些User-Agent数据;\r\n- 优化重构随机信用卡号生成逻辑，生成的卡号符合Luhn算法校验规则;\r\n- 升级依赖版本;\r\n\r\n### v1.0.14\r\n- 修订常见的地名用字，优化详细地址的随机性\r\n- 优化数字工具类 by @changhe626\r\n- 优化随机元素工具类 by @changhe626\r\n- 支持生成随机百分比\r\n- 升级依赖\r\n\r\n### v1.0.13\r\n- 日期时间数据源支持返回 java.util.Date 类型以方便使用\r\n- 新增支持随机大学专业名称\r\n- 升级依赖\r\n\r\n## 注意事项\r\n- 随机数据由程序随机生成，不存在真实性，但有可能与真实数据雷同（纯属巧合）。\r\n- 程序中使用了小部分真实数据（包括但不限于：行政区划名称、邮编、区号、高校名称、股票代码及名称等）作为基础数据源，全部来自于各个合法运营的网站上的可公开访问的网页；其中涉及的著作权或商标的所有权属于各自合法的拥有者。\r\n- 禁止利用本程序实施任何具有恶意、违反相关法律法规政策或损害他人合法权益的行为。\r\n- 本程序基于Apache协议开源，请使用者在遵守Apache协议和相关法律法规政策的前提下合理使用；使用本程序所存在的风险以及因使用本程序而产生的一切后果由使用者自己承担，程序作者不承担任何责任。\r\n\r\n## 感谢 JetBrains 免费的开源授权\r\n\u003ca href=\"https://www.jetbrains.com/?from=common-random\" target=\"_blank\"\u003e\r\n\u003cimg src=\"https://i.loli.net/2021/06/22/Kpd28P9GwhUlrck.png\" height=\"200\"/\u003e\u003c/a\u003e\r\n","funding_links":[],"categories":["Java","测试"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyindz%2Fcommon-random","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyindz%2Fcommon-random","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyindz%2Fcommon-random/lists"}