Java 生成随机数据

文章目录

1. Java-faker

依赖

xml 复制代码
<dependency>
    <groupId>com.github.javafaker</groupId>
    <artifactId>javafaker</artifactId>
    <version>1.0.2</version>
</dependency>

https://github.com/HannnnXiao/javafaker

demo

java 复制代码
		Faker faker = new Faker(Locale.CHINA); //指定地区
        final Name name = faker.name();
        System.out.println("firstName : " + name.firstName());
        System.out.println("username : " + name.username());
        System.out.println("bloodGroup : " + name.bloodGroup());
        System.out.println("suffix : " + name.suffix());
        System.out.println("title : " + name.title());
        System.out.println("lastName : " + name.lastName());
        System.out.println("nameWithMiddle : " + name.nameWithMiddle());
        System.out.println("fullName : " + name.fullName());
        System.out.println("name : " + name.name());
        System.out.println("prefix : " + name.prefix());
java 复制代码
生成结果

firstName : 熠彤
username : 烨霖.龙
bloodGroup : A-
suffix : IV
title : Investor Division Engineer
lastName : 范
nameWithMiddle : 胡思
fullName : 孟鸿涛
name : 黎航
prefix : Miss

2. common-random

依赖

xml 复制代码
<dependency>
    <groupId>com.apifan.common</groupId>
    <artifactId>common-random</artifactId>
    <version>1.0.21</version>
</dependency>

https://github.com/yindz/common-random

demo

java 复制代码
统一入口
//地区类虚拟数据
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();
相关推荐
百***35513 分钟前
Tomcat10下载安装教程
java
qq_401700415 分钟前
QT的5种标准对话框
开发语言·qt
一心只读圣贤猪27 分钟前
Canal ES Adapter pkVal 为 null 问题解决方案
java·后端
大头an33 分钟前
深入理解Spring核心原理:Bean作用域、生命周期与自动配置完全指南
java·后端
智者知已应修善业34 分钟前
【给定英文字符串统计最多小写最前输出】2023-2-27
c语言·开发语言·c++·经验分享·笔记·算法
我的golang之路果然有问题1 小时前
mac配置 unity+vscode的坑
开发语言·笔记·vscode·macos·unity·游戏引擎
铅笔小新z1 小时前
【C++】从理论到实践:类和对象完全指南(上)
开发语言·c++
rainFFrain1 小时前
qt显示类控件---QCalendarWidget
开发语言·qt
戴誉杰2 小时前
idea 2025.2 重置试用30天,无限期使用
java·ide·intellij-idea
蓁蓁啊2 小时前
ARM交叉编译中编译与链接参数不一致导致的问题
开发语言·arm开发·嵌入式硬件