Hello, I'm Kaiyuan Jun.
What I share with you today is * * [random data generator]**
Project introduction
This is an easy-to-use random data generator. It is generally used for data filling, simulation, simulation research, demonstration and other scenarios in the development and test stages. Can be integrated into various types of java Used in projects.
advantage
-
Very lightweight (less than 1M), easy to integrate, without too much third-party dependence
-
Simple and convenient, no need to write redundant code
-
The generated random data is close to the real data
Quick start
<dependency> <groupId>com.apifan.common</groupId> <artifactId>common-random</artifactId> <version>1.0.7</version> </dependency>
Random number
//Generate a random integer between 1 and 101 (excluding) int a = NumberSource.getInstance().randomInt(1, 101); //Generate 8 random integers between 1 and 101 (excluding) int[] b = NumberSource.getInstance().randomInt(1, 101, 8); //Generate a random long integer between 10000000000 and 200000000001 (excluding) long c = NumberSource.getInstance().randomLong(10000000000L, 20000000001L);
Random Chinese characters
//Generate 1 random Chinese character String i = OtherSource.getInstance().randomChinese(); //Generate 4 random Chinese characters String j = OtherSource.getInstance().randomChinese(4);
Random Chinese name
//Generate a random Chinese name (gender random) String k = PersonInfoSource.getInstance().randomChineseName(); //Generate a random male Chinese name String k2 = PersonInfoSource.getInstance().randomMaleChineseName(); //Generate a random female Chinese name String k3 = PersonInfoSource.getInstance().randomFemaleChineseName();
English name
//Generate a random English name String l = PersonInfoSource.getInstance().randomEnglishName();
Generate name Avatar
-
This function can quickly generate user avatars of various websites and app s according to user names
-
The background color is random, and the data source is from the popular colors in recent ten years. For details, see Colors of the Year
-
It supports the use of custom TTF fonts, but users need to ensure that the font copyright is legal to avoid disputes
-
This feature is not supported for use in the Android runtime environment (due to the lack of awt)
//full name String name = PersonInfoSource.getInstance().randomChineseName(); //Save path of avatar file String targetPath = "/home/user/picture/" + name + ".png; //Use default Dialog font PersonInfoSource.getInstance().generateNamePicture(name, targetPath); //Use custom fonts String font = "/home/user/font/SourceHanSansCN-Normal.ttf"; PersonInfoSource.getInstance().generateNamePicture(name, targetPath, font);
Randomly generate the virtual ID number that is in line with the rules.
//1 random ID number is generated. The area is Hebei Province, female. The date of birth is between January 11, 2001 and February 22, 2008. LocalDate beginDate2 = LocalDate.of(2001,1,11); LocalDate endDate2 = LocalDate.of(2008,2,22); String id2 = PersonInfoSource.getInstance().randomFemaleIdCard("Hebei Province", beginDate2, endDate2);
Random license plate number
//Generate 1 random Chinese mainland license plates (new energy vehicles) String n1 = OtherSource.getInstance().randomPlateNumber(true); //Generate 1 random Chinese mainland license plates (non new energy vehicles) String n2 = OtherSource.getInstance().randomPlateNumber();
Random address
//Randomly obtained provinces String prv = AreaSource.getInstance().randomProvince(); //Randomly obtain the city (province + city, separated by comma) String city = AreaSource.getInstance().randomCity(","); //Get zip code randomly String zipCode = AreaSource.getInstance().randomZipCode(); //Generate 1 random Chinese mainland addresses String addr = AreaSource.getInstance().randomAddress();
Random educational information
//Random access to education String degree = EducationSource.getInstance().randomDegree(); //Randomly obtain the name of Undergraduate University String college = EducationSource.getInstance().randomCollege(); //Random access to primary school name String primarySchoolName = EducationSource.getInstance().randomPrimarySchoolName(); //Random access to primary school grades String primarySchoolGrade = EducationSource.getInstance().randomPrimarySchoolGrade(); //Random acquisition of middle school name String highSchoolName = EducationSource.getInstance().randomHighSchoolName(); //Random acquisition of middle school grades String highSchoolGrade = EducationSource.getInstance().randomHighSchoolGrade(); //Random class name String className = EducationSource.getInstance().randomClassName();
There are many supported random types, so they are not listed here one by one. It mainly includes but is not limited to the following fields.
-
Date time
-
Geography
-
internet
-
personal information
-
education
-
finance
-
Sports
-
other
matters needing attention
-
The random data is randomly generated by the program, which is not authentic, but it may be the same as the real data (pure coincidence).
-
The program uses a small part of real data (including but not limited to: administrative division name, zip code, area code, university name, stock code and name, etc.) as the basic data source, all from publicly accessible web pages on legally operated websites; the ownership of copyright or trademark involved belongs to their respective legal owners.
Project address
https://www.github.com/shaoxiongdu/common-random
last
As usual, Amway's official account is: Tap the value of open source]
Continue to share some fun, interesting and sand carving open source projects or high-quality development tools and practical programming skills. Welcome to pay attention!
History push:
Like, look again, forward!