#generator #fake #fakedata #data-generator


Generate fake data with various generators

6 releases

0.2.4 Apr 27, 2020
0.2.3 Apr 27, 2020
0.2.2 May 2, 2019
0.1.0 Apr 24, 2019

#49 in Testing

Download history 1121/week @ 2021-06-30 1224/week @ 2021-07-07 1136/week @ 2021-07-14 955/week @ 2021-07-21 957/week @ 2021-07-28 884/week @ 2021-08-04 1317/week @ 2021-08-11 1379/week @ 2021-08-18 1241/week @ 2021-08-25 1147/week @ 2021-09-01 1748/week @ 2021-09-08 1884/week @ 2021-09-15 1033/week @ 2021-09-22 1443/week @ 2021-09-29 1805/week @ 2021-10-06 1348/week @ 2021-10-13

7,912 downloads per month

MIT license



A rust library to generate fake data

"data generator for Rust"

Build Status Crates.io Documentation at docs.rs

Table of contents


⬆️ Back to Top

This library provides functions to generate random values ("fake data"). It is in its early stages and some values are not yet fully random. Basic documentation is provided below and on https://docs.rs/fakedata_generator/.


⬆️ Back to Top

Add the library as dependency to your Cargo.toml.

fakedata_generator = "0.1.0"

Now the the library can be loaded with use fakedata_generator::*.

extern crate fakedata_generator;
use fakedata_generator::*;

fn main() {
    let random_word = gen_enum("some,random,words".to_string());
    println!("Random word is: {}", random_word); 

A full list of available generators and their function signature is shown below.


Generators without arguments

⬆️ Back to Top


Return a random e-Mail address which is a combination of the username and domain generator.

Function signature

gen_email() -> String

Example call

let email: String = gen_email();
// email = shaneIxD@we.net


Return a random username.

Note: predefined list as of v0.2.

Function signature

gen_username() -> String

Example call

let user: String = gen_username();
// user = ahmadajmi


Return a random domain name.

Note: Does not yet support all TDLs and true random host names - it's created by a predefined list.

Function signature

gen_domain() -> String

Example call

let domain: String = gen_domain();
// domain = "names.us"


Return a random HTTP method from a defined list.

Possible values: "DELETE", "GET", "HEAD", "OPTION", "PATCH", "POST", "PUT"

Function signature

gen_http_method() -> String

Example call

let method: String = gen_http_method();
// method = "GET"


Returns a random IP address. Generates four numbers in the range of 0 - 255 which are written out in the format {}.{}.{}.{}.

Function signature

gen_ipv4() -> String

Example call

let ip: String = gen_ipv4();
// ip = ""

Generators with arguments

⬆️ Back to Top


Return random string from set of specified strings. Specify a comma separated list as argument.

Function signature

gen_enum(input: String) -> String

Example call

let word: String = gen_enum("hello,hola,hallo".to_string());
// word = "hola"


Return random integer in range. Must specify 1 or 2 numbers separated by comma. If 1 argument is specified it is handled as "highest" value and 0 is used as lowest value.

Function signature

gen_int(input: String) -> String

Example call

let num: String = gen_enum("1,100".to_string());
// num = "42"

Corpora generator

⬆️ Back to Top

gen_corpora_switch is a special generator that gets its data in JSON format taken from the Corpora Project. A copy of the entire Corpora project is included in the data directory. Not all data sets are available as of now. See the src/corpora/data.rs file for all available sets.

Possible input values:

  • cat
  • dog
  • horse
  • dinosaur
  • gemstone
  • mood
  • fabric

Each of these will return a random word from the list.

Function signature

gen_corpora_switch(input: String) -> String

Example call

let word: String = gen_corpora_switch("cat".to_string());
// word = "European Shorthair"

let fabric: String = gen_corpora_switch("fabric".to_string());
// word = "longcloth"


⬆️ Back to Top

The following examples show how fakedata_generator can be used in a Rust project.

Name Description Repository
fakedata_server A HTTP API providing random values based on fakedata_generator data. View code


⬆️ Back to Top

We love and welcome every form of contribution.

Where to start?

Here are some good places to start:

Code of Conduct

⬆️ Back to Top

You are expected to follow our code of conduct when interacting with the project via issues, pull requests or in any other form. Many thanks to the awesome contributor covenant initiative!


⬆️ Back to Top

MIT License Copyright (c) 2019 Kevin Gimbel

Special Thanks to the Rust Community, Rust Language Maintainers, and JetBrains for IntelliJ IDEA. See NOTICE for full list.