#faker #data #generator #random

fake

An easy to use library for generating fake data like name, number, address, lorem, dates, etc

18 stable releases

Uses new Rust 2021

2.5.0 Jun 14, 2022
2.4.3 Nov 4, 2021
2.4.1 Aug 3, 2021
2.4.0 Dec 30, 2020
0.4.0 Jul 18, 2016

#85 in Algorithms

Download history 6051/week @ 2022-03-12 6759/week @ 2022-03-19 6926/week @ 2022-03-26 6982/week @ 2022-04-02 6624/week @ 2022-04-09 6398/week @ 2022-04-16 6390/week @ 2022-04-23 7360/week @ 2022-04-30 7379/week @ 2022-05-07 6235/week @ 2022-05-14 7592/week @ 2022-05-21 8119/week @ 2022-05-28 9663/week @ 2022-06-04 8957/week @ 2022-06-11 8744/week @ 2022-06-18 7152/week @ 2022-06-25

35,456 downloads per month
Used in 48 crates (47 directly)

MIT/Apache

290KB
6K SLoC

Fake

Build Status Latest Version

A Rust library for generating fake data.

Installation

Default (rand is required):

[dependencies]
fake = "2.5"
rand = "0.8"

If you want to use #[derive(Dummy)]:

fake = { version = "2.5", features=['derive']}

If you want the date and time features from chrono:

fake = { version = "2.5", features=['chrono']}

If you want http faker features:

fake = { version = "2.5", features=['http']}

If you want uuid faker features:

fake = { version = "2.5", features=['uuid']}

If you want rust_decimal faker features:

fake = { version = "2.5", features=['rust_decimal']}

If you want bigdecimal faker features:

fake = { version = "2.5", features=['bigdecimal']}

If you want random_color faker features:

fake = { version = "2.5", features=['random_color']}

Usage

use fake::{Dummy, Fake, Faker};
use rand::rngs::StdRng;
use rand::SeedableRng;

#[derive(Debug, Dummy)]
pub struct Foo {
    #[dummy(faker = "1000..2000")]
    order_id: usize,
    customer: String,
    paid: bool,
}

fn main() {
    // type derived Dummy
    let f: Foo = Faker.fake();
    println!("{:?}", f);

    // using `Faker` to generate default fake value of given type
    let tuple = Faker.fake::<(u8, u32, f32)>();
    println!("tuple {:?}", tuple);
    println!("String {:?}", Faker.fake::<String>());

    // types U can used to generate fake value T, if `T: Dummy<U>`
    println!("String {:?}", (8..20).fake::<String>());
    println!("u32 {:?}", (8..20).fake::<u32>());

    // using `faker` module with locales
    use fake::faker::name::raw::*;
    use fake::locales::*;

    let name: String = Name(EN).fake();
    println!("name {:?}", name);

    let name: String = Name(ZH_TW).fake();
    println!("name {:?}", name);

    // using convenient function without providing locale
    use fake::faker::lorem::en::*;
    let words: Vec<String> = Words(3..5).fake();
    println!("words {:?}", words);

    // using macro to generate nested collection
    let name_vec = fake::vec![String as Name(EN); 4, 3..5, 2];
    println!("random nested vec {:?}", name_vec);

    // fixed seed rng
    let seed = [
        1, 0, 0, 0, 23, 0, 0, 0, 200, 1, 0, 0, 210, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,
    ];
    let ref mut r = StdRng::from_seed(seed);
    for _ in 0..5 {
        let v: usize = Faker.fake_with_rng(r);
        println!("value from fixed seed {}", v);
    }
}

Fakers with locale

Lorem

Word();
Words(count: Range<usize>);
Sentence(count: Range<usize>);
Sentences(count: Range<usize>);
Paragraph(count: Range<usize>);
Paragraphs(count: Range<usize>);

Name

FirstName();
LastName();
Title();
Suffix();
Name();
NameWithTitle();

Number

Digit();
NumberWithFormat(fmt: &'static str);

Boolean

Boolean(ratio: u8);

Internet

FreeEmailProvider();
DomainSuffix();
FreeEmail();
SafeEmail();
Username();
Password(len_range: Range<usize>);
IPv4();
IPv6();
IP();
MACAddress();
UserAgent();

HTTP

RfcStatusCode();
ValidStatusCode();

Color

HexColor();
RgbColor();
RgbaColor();
HslColor();
HslaColor();
Color();

Company

CompanySuffix();
CompanyName();
Buzzword();
BuzzwordMiddle();
BuzzwordTail();
CatchPhase();
BsVerb();
BsAdj();
BsNoun();
Bs();
Profession();
Industry();

Address

CityPrefix();
CitySuffix();
CityName();
CountryName();
CountryCode();
StreetSuffix();
StreetName();
TimeZone();
StateName();
StateAbbr();
SecondaryAddressType();
SecondaryAddress();
ZipCode();
PostCode();
BuildingNumber();
Latitude();
Longitude();
Geohash(precision: u8);

Automotive

LicencePlate();

Barcode

Isbn();
Isbn13();
Isbn10();

Phone Number

PhoneNumber();
CellNumber();

Date/Time

Time();
Date();
DateTime();
Duration();
DateTimeBefore(dt: DateTime<Utc>);
DateTimeAfter(dt: DateTime<Utc>);
DateTimeBetween(start: DateTime<Utc>, end: DateTime<Utc>);

Filesystem

FilePath();
FileName();
FileExtension();
DirPath();

Finance

Bic();

UUID

UUIDv1();
UUIDv3();
UUIDv4();
UUIDv5();

LICENSE

This project is licensed under either of

at your option.

Dependencies

~0.3–1.1MB
~20K SLoC