├── .github
├── FUNDING.yml
└── workflows
│ └── go.yml
├── .gitignore
├── .vscode
└── settings.json
├── BENCHMARKS.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── address.go
├── address_test.go
├── animal.go
├── animal_test.go
├── app.go
├── app_test.go
├── auth.go
├── auth_test.go
├── beer.go
├── beer_test.go
├── book.go
├── book_test.go
├── car.go
├── car_test.go
├── celebrity.go
├── celebrity_test.go
├── cmd
├── exampleupdate
│ └── main.go
├── gofakeit
│ ├── README.md
│ ├── cmd.gif
│ ├── gofakeit.go
│ └── gofakeit_test.go
└── gofakeitserver
│ ├── README.md
│ ├── init_test.go
│ ├── main.go
│ ├── main_test.go
│ └── server.gif
├── color.go
├── color_test.go
├── company.go
├── company_test.go
├── csv.go
├── csv_test.go
├── data
├── README.md
├── address.go
├── animals.go
├── bank.go
├── beer.go
├── book.go
├── car.go
├── celebrity.go
├── colors.go
├── company.go
├── computer.go
├── currency.go
├── data.go
├── data_test.go
├── datetime.go
├── emoji.go
├── errors.go
├── files.go
├── food.go
├── hacker.go
├── hipster.go
├── html.go
├── internet.go
├── job.go
├── languages.go
├── log_level.go
├── lorem.go
├── minecraft.go
├── movie.go
├── payment.go
├── person.go
├── product.go
├── school.go
├── sentence.go
├── song.go
├── word.go
└── word_test.go
├── doc.go
├── emoji.go
├── emoji_test.go
├── error.go
├── error_test.go
├── fakeable.go
├── fakeable_external_test.go
├── fakeable_test.go
├── faker.go
├── faker_test.go
├── file.go
├── file_test.go
├── finance.go
├── finance_test.go
├── food.go
├── food_test.go
├── game.go
├── game_test.go
├── generate.go
├── generate_test.go
├── go.mod
├── go.sum
├── hacker.go
├── hacker_test.go
├── helpers.go
├── helpers_test.go
├── hipster.go
├── hipster_test.go
├── html.go
├── html_test.go
├── image.go
├── image_test.go
├── internet.go
├── internet_test.go
├── json.go
├── json_test.go
├── languages.go
├── languages_test.go
├── logo.png
├── lookup.go
├── lookup_test.go
├── lorem.go
├── lorem_test.go
├── minecraft.go
├── minecraft_test.go
├── misc.go
├── misc_test.go
├── movie.go
├── movie_test.go
├── number.go
├── number_test.go
├── payment.go
├── payment_test.go
├── person.go
├── person_test.go
├── product.go
├── product_test.go
├── school.go
├── school_test.go
├── slice.go
├── slice_test.go
├── song.go
├── song_test.go
├── source
├── BENCHMARKS.md
├── README.md
├── crypto.go
├── crypto_test.go
├── dumb.go
├── dumb_test.go
├── jsf.go
├── jsf_test.go
├── others_test.go
├── sfc.go
└── sfc_test.go
├── sql.go
├── sql_test.go
├── string.go
├── string_test.go
├── struct.go
├── struct_test.go
├── template.go
├── template_test.go
├── time.go
├── time_test.go
├── weighted.go
├── weighted_test.go
├── word_adjective.go
├── word_adjective_test.go
├── word_adverb.go
├── word_adverb_test.go
├── word_comment.go
├── word_comment_test.go
├── word_connective.go
├── word_connective_test.go
├── word_general.go
├── word_general_test.go
├── word_grammar.go
├── word_grammar_test.go
├── word_helper.go
├── word_helper_test.go
├── word_misc.go
├── word_misc_test.go
├── word_noun.go
├── word_noun_test.go
├── word_phrase.go
├── word_phrase_test.go
├── word_preposition.go
├── word_preposition_test.go
├── word_pronoun.go
├── word_pronoun_test.go
├── word_sentence.go
├── word_sentence_test.go
├── word_verb.go
├── word_verb_test.go
├── xml.go
└── xml_test.go
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: brianvoe
4 | patreon: brianvoe
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: brianvoe
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: # Replace with a single custom sponsorship URL
13 |
--------------------------------------------------------------------------------
/.github/workflows/go.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | on:
4 | push:
5 | branches: [master, develop]
6 | pull_request:
7 | branches: [master, develop]
8 |
9 | jobs:
10 | test:
11 | strategy:
12 | matrix:
13 | go: [1.22.*]
14 | os: [ubuntu-latest, macos-latest, windows-latest]
15 | runs-on: ${{ matrix.os }}
16 |
17 | name: Go ${{ matrix.go }} ${{ matrix.os }}
18 | steps:
19 | - uses: actions/checkout@v3
20 |
21 | - name: Setup Go
22 | uses: actions/setup-go@v3
23 | with:
24 | go-version: ${{ matrix.go }}
25 |
26 | - name: Test
27 | run: go test -v ./...
28 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brianvoe/gofakeit/b3820daba293d107191129e516fb396e03a70a31/.gitignore
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "go.coverOnSave": true,
3 | "go.coverOnSingleTest": true,
4 | "go.coverOnSingleTestFile": true,
5 | "go.coverShowCounts": false,
6 | "go.coverageDecorator": {
7 | "type": "gutter",
8 | "coveredHighlightColor": "rgba(64,128,128,0.5)",
9 | "uncoveredHighlightColor": "rgba(128,64,64,0.25)",
10 | "coveredGutterStyle": "slashgreen",
11 | "uncoveredGutterStyle": "slashred"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at brian@webiswhatido.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Make a pull request and submit it and ill take a look at it. Thanks!
2 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) [year] [fullname]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/animal_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExamplePetName() {
9 | Seed(11)
10 | fmt.Println(PetName())
11 |
12 | // Output: The Notorious D.O.G.
13 | }
14 |
15 | func ExampleFaker_PetName() {
16 | f := New(11)
17 | fmt.Println(f.PetName())
18 |
19 | // Output: The Notorious D.O.G.
20 | }
21 |
22 | func BenchmarkPetName(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | PetName()
25 | }
26 | }
27 |
28 | func ExampleAnimal() {
29 | Seed(11)
30 | fmt.Println(Animal())
31 |
32 | // Output: turtle
33 | }
34 |
35 | func ExampleFaker_Animal() {
36 | f := New(11)
37 | fmt.Println(f.Animal())
38 |
39 | // Output: turtle
40 | }
41 |
42 | func BenchmarkAnimal(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | Animal()
45 | }
46 | }
47 |
48 | func ExampleAnimalType() {
49 | Seed(11)
50 | fmt.Println(AnimalType())
51 |
52 | // Output: reptiles
53 | }
54 |
55 | func ExampleFaker_AnimalType() {
56 | f := New(11)
57 | fmt.Println(f.AnimalType())
58 |
59 | // Output: reptiles
60 | }
61 |
62 | func BenchmarkAnimalType(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | AnimalType()
65 | }
66 | }
67 |
68 | func ExampleFarmAnimal() {
69 | Seed(11)
70 | fmt.Println(FarmAnimal())
71 |
72 | // Output: Sheep
73 | }
74 |
75 | func ExampleFaker_FarmAnimal() {
76 | f := New(11)
77 | fmt.Println(f.FarmAnimal())
78 |
79 | // Output: Sheep
80 | }
81 |
82 | func BenchmarkFarmAnimal(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | FarmAnimal()
85 | }
86 | }
87 |
88 | func ExampleCat() {
89 | Seed(11)
90 | fmt.Println(Cat())
91 |
92 | // Output: Sokoke
93 | }
94 |
95 | func ExampleFaker_Cat() {
96 | f := New(11)
97 | fmt.Println(f.Cat())
98 |
99 | // Output: Sokoke
100 | }
101 |
102 | func BenchmarkCat(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | Cat()
105 | }
106 | }
107 |
108 | func ExampleDog() {
109 | Seed(11)
110 | fmt.Println(Dog())
111 |
112 | // Output: Rat Terrier
113 | }
114 |
115 | func ExampleFaker_Dog() {
116 | f := New(11)
117 | fmt.Println(f.Dog())
118 |
119 | // Output: Rat Terrier
120 | }
121 |
122 | func BenchmarkDog(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | Dog()
125 | }
126 | }
127 |
128 | func ExampleBird() {
129 | Seed(11)
130 | fmt.Println(Bird())
131 |
132 | // Output: toucan
133 | }
134 |
135 | func ExampleFaker_Bird() {
136 | f := New(11)
137 | fmt.Println(f.Bird())
138 |
139 | // Output: toucan
140 | }
141 |
142 | func BenchmarkBird(b *testing.B) {
143 | for i := 0; i < b.N; i++ {
144 | Bird()
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/app.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | // AppName will generate a random app name
8 | func AppName() string {
9 | return appName(GlobalFaker)
10 | }
11 |
12 | // AppName will generate a random app name
13 | func (f *Faker) AppName() string {
14 | return appName(f)
15 | }
16 |
17 | func appName(f *Faker) string {
18 | name := ""
19 | switch number(f, 1, 3) {
20 | case 1:
21 | name = noun(f) + verb(f)
22 | case 2:
23 | name = color(f) + noun(f)
24 | case 3:
25 | name = animal(f) + verb(f)
26 | }
27 |
28 | return title(name)
29 | }
30 |
31 | // AppVersion will generate a random app version
32 | func AppVersion() string {
33 | return appVersion(GlobalFaker)
34 | }
35 |
36 | // AppVersion will generate a random app version
37 | func (f *Faker) AppVersion() string {
38 | return appVersion(f)
39 | }
40 |
41 | func appVersion(f *Faker) string {
42 | return fmt.Sprintf("%d.%d.%d", number(f, 1, 5), number(f, 1, 20), number(f, 1, 20))
43 | }
44 |
45 | // AppAuthor will generate a random company or person name
46 | func AppAuthor() string {
47 | return appAuthor(GlobalFaker)
48 | }
49 |
50 | // AppAuthor will generate a random company or person name
51 | func (f *Faker) AppAuthor() string {
52 | return appAuthor(f)
53 | }
54 |
55 | func appAuthor(f *Faker) string {
56 | if boolFunc(f) {
57 | return name(f)
58 | }
59 |
60 | return company(f)
61 | }
62 |
63 | func addAppLookup() {
64 | AddFuncLookup("appname", Info{
65 | Display: "App Name",
66 | Category: "app",
67 | Description: "Software program designed for a specific purpose or task on a computer or mobile device",
68 | Example: "Parkrespond",
69 | Output: "string",
70 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
71 | return appName(f), nil
72 | },
73 | })
74 |
75 | AddFuncLookup("appversion", Info{
76 | Display: "App Version",
77 | Category: "app",
78 | Description: "Particular release of an application in Semantic Versioning format",
79 | Example: "1.12.14",
80 | Output: "string",
81 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
82 | return appVersion(f), nil
83 | },
84 | })
85 |
86 | AddFuncLookup("appauthor", Info{
87 | Display: "App Author",
88 | Category: "app",
89 | Description: "Person or group creating and developing an application",
90 | Example: "Qado Energy, Inc.",
91 | Output: "string",
92 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
93 | return appAuthor(f), nil
94 | },
95 | })
96 | }
97 |
--------------------------------------------------------------------------------
/app_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleAppName() {
9 | Seed(11)
10 | fmt.Println(AppName())
11 |
12 | // Output: Swanthink
13 | }
14 |
15 | func ExampleFaker_AppName() {
16 | f := New(11)
17 | fmt.Println(f.AppName())
18 |
19 | // Output: Swanthink
20 | }
21 |
22 | func TestAppName(t *testing.T) {
23 | for i := 0; i < 100; i++ {
24 | name := AppName()
25 | if name == "" {
26 | t.Error("app name should not be empty")
27 | }
28 | }
29 | }
30 |
31 | func BenchmarkAppName(b *testing.B) {
32 | for i := 0; i < b.N; i++ {
33 | AppName()
34 | }
35 | }
36 |
37 | func ExampleAppVersion() {
38 | Seed(11)
39 | fmt.Println(AppVersion())
40 |
41 | // Output: 5.18.4
42 | }
43 |
44 | func ExampleFaker_AppVersion() {
45 | f := New(11)
46 | fmt.Println(f.AppVersion())
47 |
48 | // Output: 5.18.4
49 | }
50 |
51 | func BenchmarkAppVersion(b *testing.B) {
52 | for i := 0; i < b.N; i++ {
53 | AppVersion()
54 | }
55 | }
56 |
57 | func ExampleAppAuthor() {
58 | Seed(11)
59 | fmt.Println(AppAuthor())
60 |
61 | // Output: StreetEasy
62 | }
63 |
64 | func ExampleFaker_AppAuthor() {
65 | f := New(11)
66 | fmt.Println(f.AppAuthor())
67 |
68 | // Output: StreetEasy
69 | }
70 |
71 | func TestAuthor(t *testing.T) {
72 | for i := 0; i < 100; i++ {
73 | author := AppAuthor()
74 | if author == "" {
75 | t.Error("app author should not be empty")
76 | }
77 | }
78 | }
79 |
80 | func BenchmarkAppAuthor(b *testing.B) {
81 | for i := 0; i < b.N; i++ {
82 | AppAuthor()
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/auth_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleUsername() {
9 | Seed(11)
10 | fmt.Println(Username())
11 |
12 | // Output: Treutel8125
13 | }
14 |
15 | func ExampleFaker_Username() {
16 | f := New(11)
17 | fmt.Println(f.Username())
18 |
19 | // Output: Treutel8125
20 | }
21 |
22 | func BenchmarkUsername(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Username()
25 | }
26 | }
27 |
28 | func TestPassword(t *testing.T) {
29 | length := 10
30 |
31 | pass := Password(true, true, true, true, true, length)
32 |
33 | if len(pass) != length {
34 | t.Error("Password length does not equal requested length")
35 | }
36 |
37 | // Test fully empty
38 | pass = Password(false, false, false, false, false, length)
39 | if pass == "" {
40 | t.Error("Password should not be empty")
41 | }
42 |
43 | // Test it doesnt start or end with a space
44 | for i := 0; i < 1000; i++ {
45 | pass = Password(true, true, true, true, true, length)
46 | if pass[0] == ' ' || pass[len(pass)-1] == ' ' {
47 | t.Error("Password should not start or end with a space")
48 | }
49 | }
50 | }
51 |
52 | func ExamplePassword() {
53 | Seed(11)
54 | fmt.Println(Password(true, false, false, false, false, 32))
55 | fmt.Println(Password(false, true, false, false, false, 32))
56 | fmt.Println(Password(false, false, true, false, false, 32))
57 | fmt.Println(Password(false, false, false, true, false, 32))
58 | fmt.Println(Password(true, true, true, true, true, 32))
59 | fmt.Println(Password(true, true, true, true, true, 4))
60 |
61 | // Output: cfelntbponnbbzrhswobuwlxajeeclrx
62 | // KYEKNGUUNKUYSFBUFFTGDKUVCVYKPONP
63 | // 43622637275953627791234759581343
64 | // @.__-._-!-!_..!-_*_*__-@*.__.__!
65 | // -DTHJ@.oF@d@L5F65 N-.@U5xWX F0DI
66 | // foZnB
67 | }
68 |
69 | func ExampleFaker_Password() {
70 | f := New(11)
71 | fmt.Println(f.Password(true, false, false, false, false, 32))
72 | fmt.Println(f.Password(false, true, false, false, false, 32))
73 | fmt.Println(f.Password(false, false, true, false, false, 32))
74 | fmt.Println(f.Password(false, false, false, true, false, 32))
75 | fmt.Println(f.Password(true, true, true, true, true, 32))
76 | fmt.Println(f.Password(true, true, true, true, true, 4))
77 |
78 | // Output: cfelntbponnbbzrhswobuwlxajeeclrx
79 | // KYEKNGUUNKUYSFBUFFTGDKUVCVYKPONP
80 | // 43622637275953627791234759581343
81 | // @.__-._-!-!_..!-_*_*__-@*.__.__!
82 | // -DTHJ@.oF@d@L5F65 N-.@U5xWX F0DI
83 | // foZnB
84 | }
85 |
86 | func BenchmarkPassword(b *testing.B) {
87 | for i := 0; i < b.N; i++ {
88 | Password(true, true, true, true, true, 50)
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/beer_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleBeerName() {
9 | Seed(11)
10 | fmt.Println(BeerName())
11 |
12 | // Output: Sierra Nevada Bigfoot Barleywine Style Ale
13 | }
14 |
15 | func ExampleFaker_BeerName() {
16 | f := New(11)
17 | fmt.Println(f.BeerName())
18 |
19 | // Output: Sierra Nevada Bigfoot Barleywine Style Ale
20 | }
21 |
22 | func BenchmarkBeerName(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | BeerName()
25 | }
26 | }
27 |
28 | func ExampleBeerStyle() {
29 | Seed(11)
30 | fmt.Println(BeerStyle())
31 |
32 | // Output: Vegetable Beer
33 | }
34 |
35 | func ExampleFaker_BeerStyle() {
36 | f := New(11)
37 | fmt.Println(f.BeerStyle())
38 |
39 | // Output: Vegetable Beer
40 | }
41 |
42 | func BenchmarkBeerStyle(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | BeerStyle()
45 | }
46 | }
47 |
48 | func ExampleBeerHop() {
49 | Seed(11)
50 | fmt.Println(BeerHop())
51 |
52 | // Output: TriplePearl
53 | }
54 |
55 | func ExampleFaker_BeerHop() {
56 | f := New(11)
57 | fmt.Println(f.BeerHop())
58 |
59 | // Output: TriplePearl
60 | }
61 |
62 | func BenchmarkBeerHop(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | BeerHop()
65 | }
66 | }
67 |
68 | func ExampleBeerYeast() {
69 | Seed(11)
70 | fmt.Println(BeerYeast())
71 |
72 | // Output: 2308 - Munich Lager
73 | }
74 |
75 | func ExampleFaker_BeerYeast() {
76 | f := New(11)
77 | fmt.Println(f.BeerYeast())
78 |
79 | // Output: 2308 - Munich Lager
80 | }
81 |
82 | func BenchmarkBeerYeast(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | BeerYeast()
85 | }
86 |
87 | }
88 |
89 | func ExampleBeerMalt() {
90 | Seed(11)
91 | fmt.Println(BeerMalt())
92 |
93 | // Output: Munich
94 | }
95 |
96 | func ExampleFaker_BeerMalt() {
97 | f := New(11)
98 | fmt.Println(f.BeerMalt())
99 |
100 | // Output: Munich
101 | }
102 |
103 | func BenchmarkBeerMalt(b *testing.B) {
104 | for i := 0; i < b.N; i++ {
105 | BeerMalt()
106 | }
107 | }
108 |
109 | func ExampleBeerIbu() {
110 | Seed(11)
111 | fmt.Println(BeerIbu())
112 |
113 | // Output: 91 IBU
114 | }
115 |
116 | func ExampleFaker_BeerIbu() {
117 | f := New(11)
118 | fmt.Println(f.BeerIbu())
119 |
120 | // Output: 91 IBU
121 | }
122 |
123 | func BenchmarkBeerIbu(b *testing.B) {
124 | for i := 0; i < b.N; i++ {
125 | BeerIbu()
126 | }
127 | }
128 |
129 | func ExampleBeerAlcohol() {
130 | Seed(11)
131 | fmt.Println(BeerAlcohol())
132 |
133 | // Output: 8.2%
134 | }
135 |
136 | func ExampleFaker_BeerAlcohol() {
137 | f := New(11)
138 | fmt.Println(f.BeerAlcohol())
139 |
140 | // Output: 8.2%
141 | }
142 |
143 | func BenchmarkBeerAlcohol(b *testing.B) {
144 | for i := 0; i < b.N; i++ {
145 | BeerAlcohol()
146 | }
147 | }
148 |
149 | func ExampleBeerBlg() {
150 | Seed(11)
151 | fmt.Println(BeerBlg())
152 |
153 | // Output: 16.6°Blg
154 | }
155 |
156 | func ExampleFaker_BeerBlg() {
157 | f := New(11)
158 | fmt.Println(f.BeerBlg())
159 |
160 | // Output: 16.6°Blg
161 | }
162 |
163 | func BenchmarkBeerBlg(b *testing.B) {
164 | for i := 0; i < b.N; i++ {
165 | BeerBlg()
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/book.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | func BookTitle() string { return bookTitle(GlobalFaker) }
4 |
5 | func (f *Faker) BookTitle() string { return bookTitle(f) }
6 |
7 | func bookTitle(f *Faker) string { return getRandValue(f, []string{"book", "title"}) }
8 |
9 | func BookAuthor() string { return bookAuthor(GlobalFaker) }
10 |
11 | func (f *Faker) BookAuthor() string { return bookAuthor(f) }
12 |
13 | func bookAuthor(f *Faker) string { return getRandValue(f, []string{"book", "author"}) }
14 |
15 | func BookGenre() string { return bookGenre(GlobalFaker) }
16 |
17 | func (f *Faker) BookGenre() string { return bookGenre(f) }
18 |
19 | func bookGenre(f *Faker) string { return getRandValue(f, []string{"book", "genre"}) }
20 |
21 | type BookInfo struct {
22 | Title string `json:"title" xml:"name"`
23 | Author string `json:"author" xml:"author"`
24 | Genre string `json:"genre" xml:"genre"`
25 | }
26 |
27 | func Book() *BookInfo { return book(GlobalFaker) }
28 |
29 | func (f *Faker) Book() *BookInfo { return book(f) }
30 |
31 | func book(f *Faker) *BookInfo {
32 | return &BookInfo{
33 | Title: bookTitle(f),
34 | Author: bookAuthor(f),
35 | Genre: bookGenre(f),
36 | }
37 | }
38 |
39 | func addBookLookup() {
40 | AddFuncLookup("book", Info{
41 | Display: "Book",
42 | Category: "book",
43 | Description: "Written or printed work consisting of pages bound together, covering various subjects or stories",
44 | Example: `{
45 | "title": "Anna Karenina",
46 | "author": "Toni Morrison",
47 | "genre": "Thriller"
48 | }`,
49 | Output: "map[string]string",
50 | ContentType: "application/json",
51 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
52 | return book(f), nil
53 | },
54 | })
55 |
56 | AddFuncLookup("booktitle", Info{
57 | Display: "Title",
58 | Category: "book",
59 | Description: "The specific name given to a book",
60 | Example: "Hamlet",
61 | Output: "string",
62 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
63 | return bookTitle(f), nil
64 | },
65 | })
66 |
67 | AddFuncLookup("bookauthor", Info{
68 | Display: "Author",
69 | Category: "book",
70 | Description: "The individual who wrote or created the content of a book",
71 | Example: "Mark Twain",
72 | Output: "string",
73 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
74 | return bookAuthor(f), nil
75 | },
76 | })
77 |
78 | AddFuncLookup("bookgenre", Info{
79 | Display: "Genre",
80 | Category: "book",
81 | Description: "Category or type of book defined by its content, style, or form",
82 | Example: "Adventure",
83 | Output: "string",
84 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
85 | return bookGenre(f), nil
86 | },
87 | })
88 | }
89 |
--------------------------------------------------------------------------------
/book_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleBook() {
9 | Seed(11)
10 | book := Book()
11 | fmt.Println(book.Title)
12 | fmt.Println(book.Author)
13 | fmt.Println(book.Genre)
14 |
15 | // Output: Things Fall Apart
16 | // Toni Morrison
17 | // Erotic
18 | }
19 |
20 | func ExampleFaker_Book() {
21 | f := New(11)
22 | book := f.Book()
23 | fmt.Println(book.Title)
24 | fmt.Println(book.Author)
25 | fmt.Println(book.Genre)
26 |
27 | // Output: Things Fall Apart
28 | // Toni Morrison
29 | // Erotic
30 | }
31 |
32 | func BenchmarkBook(b *testing.B) {
33 | for i := 0; i < b.N; i++ {
34 | Book()
35 | }
36 | }
37 |
38 | func TestBook(t *testing.T) {
39 | for i := 0; i < 100; i++ {
40 | Book()
41 | }
42 | }
43 |
44 | func ExampleBookTitle() {
45 | Seed(11)
46 | fmt.Println(BookTitle())
47 |
48 | // Output: Things Fall Apart
49 | }
50 |
51 | func ExampleFaker_BookTitle() {
52 | f := New(11)
53 | fmt.Println(f.BookTitle())
54 |
55 | // Output: Things Fall Apart
56 | }
57 |
58 | func BenchmarkBookTitle(b *testing.B) {
59 | for i := 0; i < b.N; i++ {
60 | BookTitle()
61 | }
62 | }
63 |
64 | func ExampleBookAuthor() {
65 | Seed(11)
66 | fmt.Println(BookAuthor())
67 |
68 | // Output: Vladimir Nabokov
69 | }
70 |
71 | func ExampleFaker_BookAuthor() {
72 | f := New(11)
73 | fmt.Println(f.BookAuthor())
74 |
75 | // Output: Vladimir Nabokov
76 | }
77 |
78 | func BenchmarkBookAuthor(b *testing.B) {
79 | for i := 0; i < b.N; i++ {
80 | BookAuthor()
81 | }
82 | }
83 |
84 | func ExampleBookGenre() {
85 | Seed(11)
86 | fmt.Println(BookGenre())
87 |
88 | // Output: Thriller
89 | }
90 |
91 | func ExampleFaker_BookGenre() {
92 | f := New(11)
93 | fmt.Println(f.BookGenre())
94 |
95 | // Output: Thriller
96 | }
97 |
98 | func BenchmarkBookGenre(b *testing.B) {
99 | for i := 0; i < b.N; i++ {
100 | BookGenre()
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/car_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleCar() {
9 | Seed(11)
10 | car := Car()
11 | fmt.Println(car.Brand)
12 | fmt.Println(car.Fuel)
13 | fmt.Println(car.Model)
14 | fmt.Println(car.Transmission)
15 | fmt.Println(car.Type)
16 | fmt.Println(car.Year)
17 |
18 | // Output: Dacia
19 | // CNG
20 | // Santafe 4wd
21 | // Automatic
22 | // Passenger car heavy
23 | // 1929
24 | }
25 |
26 | func ExampleFaker_Car() {
27 | f := New(11)
28 | car := f.Car()
29 | fmt.Println(car.Brand)
30 | fmt.Println(car.Fuel)
31 | fmt.Println(car.Model)
32 | fmt.Println(car.Transmission)
33 | fmt.Println(car.Type)
34 | fmt.Println(car.Year)
35 |
36 | // Output: Dacia
37 | // CNG
38 | // Santafe 4wd
39 | // Automatic
40 | // Passenger car heavy
41 | // 1929
42 | }
43 |
44 | func BenchmarkCar(b *testing.B) {
45 | for i := 0; i < b.N; i++ {
46 | Car()
47 | }
48 | }
49 |
50 | func ExampleCarType() {
51 | Seed(11)
52 | fmt.Println(CarType())
53 |
54 | // Output: Passenger car heavy
55 | }
56 |
57 | func ExampleFaker_CarType() {
58 | f := New(11)
59 | fmt.Println(f.CarType())
60 |
61 | // Output: Passenger car heavy
62 | }
63 |
64 | func BenchmarkCarType(b *testing.B) {
65 | for i := 0; i < b.N; i++ {
66 | CarType()
67 | }
68 | }
69 |
70 | func ExampleCarFuelType() {
71 | Seed(11)
72 | fmt.Println(CarFuelType())
73 |
74 | // Output: Electric
75 | }
76 |
77 | func ExampleFaker_CarFuelType() {
78 | f := New(11)
79 | fmt.Println(f.CarFuelType())
80 |
81 | // Output: Electric
82 | }
83 |
84 | func BenchmarkCarFuelType(b *testing.B) {
85 | for i := 0; i < b.N; i++ {
86 | CarFuelType()
87 | }
88 | }
89 |
90 | func ExampleCarTransmissionType() {
91 | Seed(11)
92 | fmt.Println(CarTransmissionType())
93 |
94 | // Output: Manual
95 | }
96 |
97 | func ExampleFaker_CarTransmissionType() {
98 | f := New(11)
99 | fmt.Println(f.CarTransmissionType())
100 |
101 | // Output: Manual
102 | }
103 |
104 | func BenchmarkCarTransmissionType(b *testing.B) {
105 | for i := 0; i < b.N; i++ {
106 | CarTransmissionType()
107 | }
108 | }
109 |
110 | func ExampleCarMaker() {
111 | Seed(11)
112 | fmt.Println(CarMaker())
113 |
114 | // Output: Spyker
115 | }
116 |
117 | func ExampleFaker_CarMaker() {
118 | f := New(11)
119 | fmt.Println(f.CarMaker())
120 |
121 | // Output: Spyker
122 | }
123 |
124 | func BenchmarkCarMaker(b *testing.B) {
125 | for i := 0; i < b.N; i++ {
126 | CarMaker()
127 | }
128 | }
129 |
130 | func ExampleCarModel() {
131 | Seed(11)
132 | fmt.Println(CarModel())
133 |
134 | // Output: Prius
135 | }
136 |
137 | func ExampleFaker_CarModel() {
138 | f := New(11)
139 | fmt.Println(f.CarModel())
140 |
141 | // Output: Prius
142 | }
143 |
144 | func BenchmarkCarModel(b *testing.B) {
145 | for i := 0; i < b.N; i++ {
146 | CarModel()
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/celebrity.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | // CelebrityActor will generate a random celebrity actor
4 | func CelebrityActor() string { return celebrityActor(GlobalFaker) }
5 |
6 | // CelebrityActor will generate a random celebrity actor
7 | func (f *Faker) CelebrityActor() string { return celebrityActor(f) }
8 |
9 | func celebrityActor(f *Faker) string { return getRandValue(f, []string{"celebrity", "actor"}) }
10 |
11 | // CelebrityBusiness will generate a random celebrity business person
12 | func CelebrityBusiness() string { return celebrityBusiness(GlobalFaker) }
13 |
14 | // CelebrityBusiness will generate a random celebrity business person
15 | func (f *Faker) CelebrityBusiness() string { return celebrityBusiness(f) }
16 |
17 | func celebrityBusiness(f *Faker) string {
18 | return getRandValue(f, []string{"celebrity", "business"})
19 | }
20 |
21 | // CelebritySport will generate a random celebrity sport person
22 | func CelebritySport() string { return celebritySport(GlobalFaker) }
23 |
24 | // CelebritySport will generate a random celebrity sport person
25 | func (f *Faker) CelebritySport() string { return celebritySport(f) }
26 |
27 | func celebritySport(f *Faker) string { return getRandValue(f, []string{"celebrity", "sport"}) }
28 |
29 | func addCelebrityLookup() {
30 | AddFuncLookup("celebrityactor", Info{
31 | Display: "Celebrity Actor",
32 | Category: "celebrity",
33 | Description: "Famous person known for acting in films, television, or theater",
34 | Example: "Brad Pitt",
35 | Output: "string",
36 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
37 | return celebrityActor(f), nil
38 | },
39 | })
40 |
41 | AddFuncLookup("celebritybusiness", Info{
42 | Display: "Celebrity Business",
43 | Category: "celebrity",
44 | Description: "High-profile individual known for significant achievements in business or entrepreneurship",
45 | Example: "Elon Musk",
46 | Output: "string",
47 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
48 | return celebrityBusiness(f), nil
49 | },
50 | })
51 |
52 | AddFuncLookup("celebritysport", Info{
53 | Display: "Celebrity Sport",
54 | Category: "celebrity",
55 | Description: "Famous athlete known for achievements in a particular sport",
56 | Example: "Michael Phelps",
57 | Output: "string",
58 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
59 | return celebritySport(f), nil
60 | },
61 | })
62 | }
63 |
--------------------------------------------------------------------------------
/celebrity_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleCelebrityActor() {
9 | Seed(11)
10 | fmt.Println(CelebrityActor())
11 |
12 | // Output: Shah Rukh Khan
13 | }
14 |
15 | func ExampleFaker_CelebrityActor() {
16 | f := New(11)
17 | fmt.Println(f.CelebrityActor())
18 |
19 | // Output: Shah Rukh Khan
20 | }
21 |
22 | func BenchmarkCelebrityActor(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | CelebrityActor()
25 | }
26 | }
27 |
28 | func ExampleCelebrityBusiness() {
29 | Seed(11)
30 | fmt.Println(CelebrityBusiness())
31 |
32 | // Output: Prescott Bush
33 | }
34 |
35 | func ExampleFaker_CelebrityBusiness() {
36 | f := New(11)
37 | fmt.Println(f.CelebrityBusiness())
38 |
39 | // Output: Prescott Bush
40 | }
41 |
42 | func BenchmarkCelebrityBusiness(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | CelebrityBusiness()
45 | }
46 | }
47 |
48 | func ExampleCelebritySport() {
49 | Seed(11)
50 | fmt.Println(CelebritySport())
51 |
52 | // Output: Grete Waitz
53 | }
54 |
55 | func ExampleFaker_CelebritySport() {
56 | f := New(11)
57 | fmt.Println(f.CelebritySport())
58 |
59 | // Output: Grete Waitz
60 | }
61 |
62 | func BenchmarkCelebritySport(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | CelebritySport()
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/cmd/gofakeit/README.md:
--------------------------------------------------------------------------------
1 | # Gofakeit Command Line Tool
2 |
3 | Run gofakeit via that command line.
4 | All functions are available to run in lowercase and if they require additional parameters you may pass by space seperation.
5 |
6 | ### Installation
7 |
8 | ```go
9 | go install -v github.com/brianvoe/gofakeit/v7/cmd/gofakeit@latest
10 | ```
11 |
12 | ### Example
13 |
14 | ```bash
15 | gofakeit firstname // billy
16 | gofakeit sentence 5 // Exercitationem occaecati sed dignissimos inventore.
17 | gofakeit shufflestrings hello,world,whats,up // up,hello,whats,world
18 |
19 | // You can also pass in a length flag to output a specific function multiple times
20 | gofakeit sentence -loop=5
21 | ```
22 |
23 | ### List of available functions
24 |
25 | ```bash
26 | gofakeit list
27 |
28 | // You may also pass a category and/or function to get a specific function data
29 | gofakeit list [category] [function]
30 | ```
31 |
32 | 
33 |
--------------------------------------------------------------------------------
/cmd/gofakeit/cmd.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brianvoe/gofakeit/b3820daba293d107191129e516fb396e03a70a31/cmd/gofakeit/cmd.gif
--------------------------------------------------------------------------------
/cmd/gofakeitserver/README.md:
--------------------------------------------------------------------------------
1 | # Gofakeit Server
2 | Run gofakeit via a running server.
3 | All functions are available to run in lowercase as first path and if they take in additional parameters you may pass by query parameters.
4 |
5 | ### Installation
6 | ```go
7 | go get -u github.com/brianvoe/gofakeit/v7/cmd/gofakeitserver
8 | ```
9 |
10 | ### Example
11 | ```bash
12 | gofakeitserver // default port is 8080
13 | ```
14 |
15 | 
--------------------------------------------------------------------------------
/cmd/gofakeitserver/init_test.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "bytes"
5 | "encoding/json"
6 | "io"
7 | "io/ioutil"
8 | "net/http"
9 | "net/http/httptest"
10 | "net/url"
11 | "reflect"
12 | "strings"
13 | "testing"
14 |
15 | "github.com/brianvoe/gofakeit/v7"
16 | )
17 |
18 | var ts *httptest.Server
19 |
20 | func init() {
21 | // Set random seed for app
22 | gofakeit.Seed(0)
23 |
24 | // Set up test server
25 | mux := http.NewServeMux()
26 | routes(mux)
27 | ts = httptest.NewServer(mux)
28 | }
29 |
30 | type testRequestStruct struct {
31 | Testing *testing.T
32 | Method string
33 | Path string
34 | ContentType string
35 | QueryParams url.Values
36 | Headers map[string]string
37 | Body any
38 |
39 | Response any
40 | StatusCode *int
41 | }
42 |
43 | func testRequest(tr *testRequestStruct) {
44 | // Make sure testing is set
45 | if tr.Testing == nil {
46 | panic("Must set testing")
47 | }
48 |
49 | if tr.ContentType == "" {
50 | tr.ContentType = "application/json"
51 | }
52 |
53 | // Check body and convert to io.Reader if body is passed
54 | var body io.Reader
55 | if tr.Body != nil {
56 | if tr.ContentType == "application/json" {
57 | typeOf := reflect.TypeOf(tr.Body).String()
58 | if strings.Contains(typeOf, "map") {
59 | jsonValue, err := json.Marshal(tr.Body)
60 | if err != nil {
61 | tr.Testing.Fatal("Unable to marshal Body")
62 | return
63 | }
64 | body = bytes.NewBuffer(jsonValue)
65 | } else if typeOf == "string" {
66 | body = bytes.NewBuffer([]byte(tr.Body.(string)))
67 | } else if typeOf == "[]uint8" {
68 | body = bytes.NewBuffer(tr.Body.([]byte))
69 | } else {
70 | jsonValue, err := json.Marshal(tr.Body)
71 | if err != nil {
72 | tr.Testing.Fatal("Unable to marshal Body")
73 | return
74 | }
75 | body = bytes.NewBuffer(jsonValue)
76 | }
77 | } else {
78 | body = bytes.NewBuffer([]byte(tr.Body.(string)))
79 | }
80 | }
81 |
82 | // Put together request
83 | req, err := http.NewRequest(tr.Method, ts.URL+"/"+strings.TrimLeft(tr.Path, "/"), body)
84 | if err != nil {
85 | tr.Testing.Fatal(err)
86 | }
87 |
88 | // Set Content Type
89 | req.Header.Set("Content-Type", tr.ContentType)
90 |
91 | // Add headers
92 | for key, value := range tr.Headers {
93 | req.Header.Set(key, value)
94 | }
95 |
96 | // Add query parameters
97 | if tr.QueryParams != nil {
98 | req.URL.RawQuery = tr.QueryParams.Encode()
99 | }
100 |
101 | // Make request
102 | resp, err := http.DefaultClient.Do(req)
103 | if err != nil {
104 | tr.Testing.Fatal(err)
105 | }
106 | defer resp.Body.Close()
107 | contentType := resp.Header.Get("Content-Type")
108 |
109 | // Read body
110 | respBody, err := ioutil.ReadAll(resp.Body)
111 | if err != nil {
112 | tr.Testing.Fatal(err)
113 | }
114 |
115 | // Get http status code
116 | if tr.StatusCode != nil {
117 | *tr.StatusCode = resp.StatusCode
118 | }
119 |
120 | // Unmarshal to response
121 | if tr.Response != nil {
122 | // Check content type
123 | switch contentType {
124 | case "application/json; charset=utf-8":
125 | if err := json.Unmarshal(respBody, tr.Response); err != nil {
126 | if ute, ok := err.(*json.UnmarshalTypeError); ok {
127 | tr.Testing.Fatalf("UnmarshalTypeError %v: %v - %v - %v\n", ute.Field, ute.Value, ute.Type, ute.Offset)
128 | } else {
129 | tr.Testing.Fatal("Unmarshal error: ", err)
130 | }
131 | }
132 | case "text/plain; charset=utf-8":
133 | *tr.Response.(*string) = string(respBody)
134 | }
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/cmd/gofakeitserver/server.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brianvoe/gofakeit/b3820daba293d107191129e516fb396e03a70a31/cmd/gofakeitserver/server.gif
--------------------------------------------------------------------------------
/color.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "github.com/brianvoe/gofakeit/v7/data"
5 | )
6 |
7 | // Color will generate a random color string
8 | func Color() string { return color(GlobalFaker) }
9 |
10 | // Color will generate a random color string
11 | func (f *Faker) Color() string { return color(f) }
12 |
13 | func color(f *Faker) string { return getRandValue(f, []string{"color", "full"}) }
14 |
15 | // NiceColor will generate a random safe color string
16 | func NiceColors() []string { return niceColors(GlobalFaker) }
17 |
18 | // NiceColor will generate a random safe color string
19 | func (f *Faker) NiceColors() []string { return niceColors(f) }
20 |
21 | func niceColors(f *Faker) []string {
22 | return data.ColorsNice[randIntRange(f, 0, len(data.ColorsNice)-1)]
23 | }
24 |
25 | // SafeColor will generate a random safe color string
26 | func SafeColor() string { return safeColor(GlobalFaker) }
27 |
28 | // SafeColor will generate a random safe color string
29 | func (f *Faker) SafeColor() string { return safeColor(f) }
30 |
31 | func safeColor(f *Faker) string { return getRandValue(f, []string{"color", "safe"}) }
32 |
33 | // HexColor will generate a random hexadecimal color string
34 | func HexColor() string { return hexColor(GlobalFaker) }
35 |
36 | // HexColor will generate a random hexadecimal color string
37 | func (f *Faker) HexColor() string { return hexColor(f) }
38 |
39 | func hexColor(f *Faker) string {
40 | color := make([]byte, 6)
41 | hashQuestion := []byte("?#")
42 | for i := 0; i < 6; i++ {
43 | color[i] = hashQuestion[f.IntN(2)]
44 | }
45 |
46 | return "#" + replaceWithHexLetters(f, replaceWithNumbers(f, string(color)))
47 | }
48 |
49 | // RGBColor will generate a random int slice color
50 | func RGBColor() []int { return rgbColor(GlobalFaker) }
51 |
52 | // RGBColor will generate a random int slice color
53 | func (f *Faker) RGBColor() []int { return rgbColor(f) }
54 |
55 | func rgbColor(f *Faker) []int {
56 | return []int{randIntRange(f, 0, 255), randIntRange(f, 0, 255), randIntRange(f, 0, 255)}
57 | }
58 |
59 | func addColorLookup() {
60 | AddFuncLookup("color", Info{
61 | Display: "Color",
62 | Category: "color",
63 | Description: "Hue seen by the eye, returns the name of the color like red or blue",
64 | Example: "MediumOrchid",
65 | Output: "string",
66 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
67 | return color(f), nil
68 | },
69 | })
70 |
71 | AddFuncLookup("nicecolors", Info{
72 | Display: "Nice Colors",
73 | Category: "color",
74 | Description: "Attractive and appealing combinations of colors, returns an list of color hex codes",
75 | Example: `["#cfffdd","#b4dec1","#5c5863","#a85163","#ff1f4c"]`,
76 | Output: "[]string",
77 | ContentType: "application/json",
78 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
79 | return niceColors(f), nil
80 | },
81 | })
82 |
83 | AddFuncLookup("safecolor", Info{
84 | Display: "Safe Color",
85 | Category: "color",
86 | Description: "Colors displayed consistently on different web browsers and devices",
87 | Example: "black",
88 | Output: "string",
89 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
90 | return safeColor(f), nil
91 | },
92 | })
93 |
94 | AddFuncLookup("hexcolor", Info{
95 | Display: "Hex Color",
96 | Category: "color",
97 | Description: "Six-digit code representing a color in the color model",
98 | Example: "#a99fb4",
99 | Output: "string",
100 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
101 | return hexColor(f), nil
102 | },
103 | })
104 |
105 | AddFuncLookup("rgbcolor", Info{
106 | Display: "RGB Color",
107 | Category: "color",
108 | Description: "Color defined by red, green, and blue light values",
109 | Example: "[85, 224, 195]",
110 | Output: "[]int",
111 | ContentType: "application/json",
112 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
113 | return rgbColor(f), nil
114 | },
115 | })
116 | }
117 |
--------------------------------------------------------------------------------
/color_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleColor() {
9 | Seed(11)
10 | fmt.Println(Color())
11 |
12 | // Output: SlateGray
13 | }
14 |
15 | func ExampleFaker_Color() {
16 | f := New(11)
17 | fmt.Println(f.Color())
18 |
19 | // Output: SlateGray
20 | }
21 |
22 | func BenchmarkColor(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Color()
25 | }
26 | }
27 |
28 | func ExampleNiceColors() {
29 | Seed(11)
30 | fmt.Println(NiceColors())
31 |
32 | // Output: [#fffbb7 #a6f6af #66b6ab #5b7c8d #4f2958]
33 | }
34 |
35 | func ExampleFaker_NiceColors() {
36 | f := New(11)
37 | fmt.Println(f.NiceColors())
38 |
39 | // Output: [#fffbb7 #a6f6af #66b6ab #5b7c8d #4f2958]
40 | }
41 |
42 | func BenchmarkNiceColors(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | NiceColors()
45 | }
46 | }
47 |
48 | func ExampleSafeColor() {
49 | Seed(11)
50 | fmt.Println(SafeColor())
51 |
52 | // Output: aqua
53 | }
54 |
55 | func ExampleFaker_SafeColor() {
56 | f := New(11)
57 | fmt.Println(f.SafeColor())
58 |
59 | // Output: aqua
60 | }
61 |
62 | func BenchmarkSafeColor(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | SafeColor()
65 | }
66 | }
67 |
68 | func ExampleHexColor() {
69 | Seed(11)
70 | fmt.Println(HexColor())
71 |
72 | // Output: #ef759a
73 | }
74 |
75 | func ExampleFaker_HexColor() {
76 | f := New(11)
77 | fmt.Println(f.HexColor())
78 |
79 | // Output: #ef759a
80 | }
81 |
82 | func BenchmarkHexColor(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | HexColor()
85 | }
86 | }
87 |
88 | func ExampleRGBColor() {
89 | Seed(11)
90 | fmt.Println(RGBColor())
91 |
92 | // Output: [180 18 181]
93 | }
94 |
95 | func ExampleFaker_RGBColor() {
96 | f := New(11)
97 | fmt.Println(f.RGBColor())
98 |
99 | // Output: [180 18 181]
100 | }
101 |
102 | func BenchmarkRGBColor(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | RGBColor()
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/company_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleCompany() {
9 | Seed(11)
10 | fmt.Println(Company())
11 |
12 | // Output: TransparaGov
13 | }
14 |
15 | func ExampleFaker_Company() {
16 | f := New(11)
17 | fmt.Println(f.Company())
18 |
19 | // Output: TransparaGov
20 | }
21 |
22 | func BenchmarkCompany(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Company()
25 | }
26 | }
27 |
28 | func TestCompany(t *testing.T) {
29 | for i := 0; i < 100; i++ {
30 | Company()
31 | }
32 | }
33 |
34 | func ExampleCompanySuffix() {
35 | Seed(11)
36 | fmt.Println(CompanySuffix())
37 |
38 | // Output: Inc
39 | }
40 |
41 | func ExampleFaker_CompanySuffix() {
42 | f := New(11)
43 | fmt.Println(f.CompanySuffix())
44 |
45 | // Output: Inc
46 | }
47 |
48 | func BenchmarkCompanySuffix(b *testing.B) {
49 | for i := 0; i < b.N; i++ {
50 | CompanySuffix()
51 | }
52 | }
53 |
54 | func ExampleBlurb() {
55 | Seed(11)
56 | fmt.Println(Blurb())
57 |
58 | // Output: Teamwork
59 | }
60 |
61 | func ExampleFaker_Blurb() {
62 | f := New(11)
63 | fmt.Println(f.Blurb())
64 |
65 | // Output: Teamwork
66 | }
67 |
68 | func BenchmarkBlurb(b *testing.B) {
69 | for i := 0; i < b.N; i++ {
70 | Blurb()
71 | }
72 | }
73 | func ExampleBuzzWord() {
74 | Seed(11)
75 | fmt.Println(BuzzWord())
76 |
77 | // Output: open system
78 | }
79 |
80 | func ExampleFaker_BuzzWord() {
81 | f := New(11)
82 | fmt.Println(f.BuzzWord())
83 |
84 | // Output: open system
85 | }
86 |
87 | func BenchmarkBuzzWord(b *testing.B) {
88 | for i := 0; i < b.N; i++ {
89 | BuzzWord()
90 | }
91 | }
92 |
93 | func ExampleBS() {
94 | Seed(11)
95 | fmt.Println(BS())
96 |
97 | // Output: models
98 | }
99 |
100 | func ExampleFaker_BS() {
101 | f := New(11)
102 | fmt.Println(f.BS())
103 |
104 | // Output: models
105 | }
106 |
107 | func BenchmarkBS(b *testing.B) {
108 | for i := 0; i < b.N; i++ {
109 | BS()
110 | }
111 | }
112 |
113 | func ExampleJob() {
114 | Seed(11)
115 | jobInfo := Job()
116 | fmt.Println(jobInfo.Company)
117 | fmt.Println(jobInfo.Title)
118 | fmt.Println(jobInfo.Descriptor)
119 | fmt.Println(jobInfo.Level)
120 |
121 | // Output: TransparaGov
122 | // Specialist
123 | // Direct
124 | // Configuration
125 | }
126 |
127 | func ExampleFaker_Job() {
128 | f := New(11)
129 | jobInfo := f.Job()
130 | fmt.Println(jobInfo.Company)
131 | fmt.Println(jobInfo.Title)
132 | fmt.Println(jobInfo.Descriptor)
133 | fmt.Println(jobInfo.Level)
134 |
135 | // Output: TransparaGov
136 | // Specialist
137 | // Direct
138 | // Configuration
139 | }
140 |
141 | func BenchmarkJob(b *testing.B) {
142 | for i := 0; i < b.N; i++ {
143 | Job()
144 | }
145 | }
146 |
147 | func ExampleJobTitle() {
148 | Seed(11)
149 | fmt.Println(JobTitle())
150 |
151 | // Output: Strategist
152 | }
153 |
154 | func ExampleFaker_JobTitle() {
155 | f := New(11)
156 | fmt.Println(f.JobTitle())
157 |
158 | // Output: Strategist
159 | }
160 |
161 | func BenchmarkJobTitle(b *testing.B) {
162 | for i := 0; i < b.N; i++ {
163 | JobTitle()
164 | }
165 | }
166 |
167 | func ExampleJobDescriptor() {
168 | Seed(11)
169 | fmt.Println(JobDescriptor())
170 |
171 | // Output: Product
172 | }
173 |
174 | func ExampleFaker_JobDescriptor() {
175 | f := New(11)
176 | fmt.Println(f.JobDescriptor())
177 |
178 | // Output: Product
179 | }
180 |
181 | func BenchmarkJobDescriptor(b *testing.B) {
182 | for i := 0; i < b.N; i++ {
183 | JobDescriptor()
184 | }
185 | }
186 |
187 | func ExampleJobLevel() {
188 | Seed(11)
189 | fmt.Println(JobLevel())
190 |
191 | // Output: Solutions
192 | }
193 |
194 | func ExampleFaker_JobLevel() {
195 | f := New(11)
196 | fmt.Println(f.JobLevel())
197 |
198 | // Output: Solutions
199 | }
200 |
201 | func BenchmarkJobLevel(b *testing.B) {
202 | for i := 0; i < b.N; i++ {
203 | JobLevel()
204 | }
205 | }
206 |
207 | func ExampleSlogan() {
208 | Seed(11)
209 | fmt.Println(Slogan())
210 |
211 | // Output: local area network maximize Drive, mission-critical.
212 | }
213 |
214 | func ExampleFaker_Slogan() {
215 | f := New(11)
216 | fmt.Println(f.Slogan())
217 |
218 | // Output: local area network maximize Drive, mission-critical.
219 | }
220 |
221 | func BenchmarkSlogan(b *testing.B) {
222 | for i := 0; i < b.N; i++ {
223 | Slogan()
224 | }
225 | }
226 |
--------------------------------------------------------------------------------
/csv_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 | "testing"
7 | )
8 |
9 | func ExampleCSV_array() {
10 | Seed(11)
11 |
12 | value, err := CSV(&CSVOptions{
13 | RowCount: 3,
14 | Fields: []Field{
15 | {Name: "id", Function: "autoincrement"},
16 | {Name: "first_name", Function: "firstname"},
17 | {Name: "last_name", Function: "lastname"},
18 | {Name: "password", Function: "password", Params: MapParams{"special": {"false"}}},
19 | },
20 | })
21 | if err != nil {
22 | fmt.Println(err)
23 | }
24 |
25 | fmt.Println(string(value))
26 |
27 | // Output: id,first_name,last_name,password
28 | // 1,Sonny,Stiedemann,8nwf0o3sBXcR
29 | // 2,Verda,Brakus,3beWLpq75Lua
30 | // 3,Jules,Cremin,Uu38J14Y8W82
31 | }
32 |
33 | func ExampleFaker_CSV_array() {
34 | f := New(11)
35 |
36 | value, err := f.CSV(&CSVOptions{
37 | RowCount: 3,
38 | Fields: []Field{
39 | {Name: "id", Function: "autoincrement"},
40 | {Name: "first_name", Function: "firstname"},
41 | {Name: "last_name", Function: "lastname"},
42 | {Name: "password", Function: "password", Params: MapParams{"special": {"false"}}},
43 | },
44 | })
45 | if err != nil {
46 | fmt.Println(err)
47 | }
48 |
49 | fmt.Println(string(value))
50 |
51 | // Output: id,first_name,last_name,password
52 | // 1,Sonny,Stiedemann,8nwf0o3sBXcR
53 | // 2,Verda,Brakus,3beWLpq75Lua
54 | // 3,Jules,Cremin,Uu38J14Y8W82
55 | }
56 |
57 | func TestCSVLookup(t *testing.T) {
58 | faker := New(0)
59 |
60 | info := GetFuncLookup("csv")
61 |
62 | m := MapParams{
63 | "rowcount": {"10"},
64 | "fields": {
65 | `{"name":"id","function":"autoincrement"}`,
66 | `{"name":"first_name","function":"firstname"}`,
67 | `{"name":"password","function":"password","params":{"special":["false"],"length":["20"]}}`,
68 | `{"name":"address","function":"address"}`,
69 | `{
70 | "name":"json",
71 | "function":"json",
72 | "params":{
73 | "type":"object",
74 | "fields":[
75 | {"name":"id","function":"autoincrement"},
76 | {"name":"first_name","function":"firstname"},
77 | {"name":"last_name","function":"lastname"},
78 | {"name":"password","function":"password","params":{"special":"false","length":"20"}}
79 | ]
80 | }
81 | }`,
82 | },
83 | }
84 |
85 | output, err := info.Generate(faker, &m, info)
86 | if err != nil {
87 | t.Fatal(err.Error())
88 | }
89 |
90 | value := string(output.([]byte))
91 |
92 | // Check that value has the correct number of rows via new line characters plus 1 for the header
93 | if strings.Count(value, "\n") != 11 {
94 | t.Error("Expected 10+1(header row) rows, got", strings.Count(value, "\n")+1)
95 | }
96 |
97 | // t.Fatal(fmt.Sprintf("%s", value.([]byte)))
98 | }
99 |
100 | func TestCSVNoOptions(t *testing.T) {
101 | Seed(11)
102 |
103 | // if CSVOptions is nil -> get a random CSVOptions
104 | _, err := CSV(nil)
105 | if err != nil {
106 | t.Fatal(err.Error())
107 | }
108 | }
109 |
110 | func BenchmarkCSVLookup100(b *testing.B) {
111 | faker := New(0)
112 |
113 | for i := 0; i < b.N; i++ {
114 | info := GetFuncLookup("csv")
115 | m := MapParams{
116 | "rowcount": {"100"},
117 | "fields": {
118 | `{"name":"id","function":"autoincrement"}`,
119 | `{"name":"first_name","function":"firstname"}`,
120 | `{"name":"last_name","function":"lastname"}`,
121 | `{"name":"password","function":"password"}`,
122 | `{"name":"description","function":"paragraph"}`,
123 | `{"name":"created_at","function":"date"}`,
124 | },
125 | }
126 | _, err := info.Generate(faker, &m, info)
127 | if err != nil {
128 | b.Fatal(err.Error())
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/data/README.md:
--------------------------------------------------------------------------------
1 | # Gofakeit Data
2 |
3 | Gofakeit data set
4 |
5 | ## List
6 |
7 | ```go
8 | List()
9 | ```
10 |
11 | ## Get/Set/Remove Data
12 |
13 | ```go
14 | data.Get("desserts")
15 |
16 | data.Set("desserts", map[string][]string{
17 | "cake": {"chocolate", "vanilla"},
18 | "pie": {"apple", "pecan"},
19 | "ice cream": {"strawberry", "vanilla"},
20 | })
21 |
22 | data.Remove("desserts")
23 | ```
24 |
25 | ## Get/Set/Remove Sub Data
26 |
27 | ```go
28 | data.GetSubData("desserts", "cake")
29 |
30 | data.SetSub("desserts", "cake", []string{"chocolate", "vanilla"})
31 |
32 | data.RemoveSub("desserts", "cake")
33 | ```
34 |
--------------------------------------------------------------------------------
/data/bank.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | var Bank = map[string][]string{
4 | "name": {
5 | "Agricultural Bank of China",
6 | "BNP Paribas",
7 | "Banco Bilbao Vizcaya Argentaria",
8 | "Banco Santander",
9 | "Bank of America",
10 | "Bank of China",
11 | "Bank of Communications",
12 | "Barclays",
13 | "Capital One Financial Corporation",
14 | "China Citic Bank",
15 | "China Construction Bank Corporation",
16 | "China Everbright Bank",
17 | "China Merchants Bank",
18 | "China Minsheng Bank",
19 | "Citigroup",
20 | "Commonwealth Bank Group",
21 | "Credit Agricole Group",
22 | "Credit Mutuel",
23 | "Deutsche Bank",
24 | "Goldman Sachs",
25 | "Groupe BPCE",
26 | "HDFC Bank",
27 | "HSBC Holdings",
28 | "Hua Xia Bank",
29 | "ING Group",
30 | "Industrial Bank",
31 | "Industrial and Commercial Bank of China",
32 | "Intesa Sanpaolo",
33 | "JP Morgan Chase & Co",
34 | "Lloyds Banking Group",
35 | "Mitsubishi UFJ Financial Group",
36 | "Mizuho Financial Group",
37 | "Morgan Stanley",
38 | "PNC Financial Services Group",
39 | "Ping An Bank",
40 | "Postal Savings Bank of China",
41 | "Rabobank Group",
42 | "Royal Bank of Canada",
43 | "Sberbank",
44 | "Scotiabank",
45 | "Shanghai Pudong Development Bank",
46 | "Societe Generale",
47 | "State Bank of India",
48 | "Sumitomo Mitsui Financial Group",
49 | "Toronto Dominion Bank",
50 | "Truist Bank",
51 | "UBS",
52 | "US Bancorp",
53 | "UniCredit",
54 | "Wells Fargo & Co",
55 | },
56 | "type": {
57 | "Central Bank",
58 | "Commercial Bank",
59 | "Cooperative Bank",
60 | "Investment Bank",
61 | "Online Bank",
62 | "Policy Bank",
63 | "Private Bank",
64 | "Retail Bank",
65 | "Savings Bank",
66 | },
67 | }
68 |
--------------------------------------------------------------------------------
/data/beer.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Beer consists of various beer information
4 | var Beer = map[string][]string{
5 | "name": {"Pliny The Elder", "Founders Kentucky Breakfast", "Trappistes Rochefort 10", "HopSlam Ale", "Stone Imperial Russian Stout", "St. Bernardus Abt 12", "Founders Breakfast Stout", "Weihenstephaner Hefeweissbier", "Péché Mortel", "Celebrator Doppelbock", "Duvel", "Dreadnaught IPA", "Nugget Nectar", "La Fin Du Monde", "Bourbon County Stout", "Old Rasputin Russian Imperial Stout", "Two Hearted Ale", "Ruination IPA", "Schneider Aventinus", "Double Bastard Ale", "90 Minute IPA", "Hop Rod Rye", "Trappistes Rochefort 8", "Chimay Grande Réserve", "Stone IPA", "Arrogant Bastard Ale", "Edmund Fitzgerald Porter", "Chocolate St", "Oak Aged Yeti Imperial Stout", "Ten FIDY", "Storm King Stout", "Shakespeare Oatmeal", "Alpha King Pale Ale", "Westmalle Trappist Tripel", "Samuel Smith’s Imperial IPA", "Yeti Imperial Stout", "Hennepin", "Samuel Smith’s Oatmeal Stout", "Brooklyn Black", "Oaked Arrogant Bastard Ale", "Sublimely Self-Righteous Ale", "Trois Pistoles", "Bell’s Expedition", "Sierra Nevada Celebration Ale", "Sierra Nevada Bigfoot Barleywine Style Ale", "Racer 5 India Pale Ale, Bear Republic Bre", "Orval Trappist Ale", "Hercules Double IPA", "Maharaj", "Maudite"},
6 | "hop": {"Ahtanum", "Amarillo", "Bitter Gold", "Bravo", "Brewer’s Gold", "Bullion", "Cascade", "Cashmere", "Centennial", "Chelan", "Chinook", "Citra", "Cluster", "Columbia", "Columbus", "Comet", "Crystal", "Equinox", "Eroica", "Fuggle", "Galena", "Glacier", "Golding", "Hallertau", "Horizon", "Liberty", "Magnum", "Millennium", "Mosaic", "Mt. Hood", "Mt. Rainier", "Newport", "Northern Brewer", "Nugget", "Olympic", "Palisade", "Perle", "Saaz", "Santiam", "Simcoe", "Sorachi Ace", "Sterling", "Summit", "Tahoma", "Tettnang", "TriplePearl", "Ultra", "Vanguard", "Warrior", "Willamette", "Yakima Gol"},
7 | "yeast": {"1007 - German Ale", "1010 - American Wheat", "1028 - London Ale", "1056 - American Ale", "1084 - Irish Ale", "1098 - British Ale", "1099 - Whitbread Ale", "1187 - Ringwood Ale", "1272 - American Ale II", "1275 - Thames Valley Ale", "1318 - London Ale III", "1332 - Northwest Ale", "1335 - British Ale II", "1450 - Dennys Favorite 50", "1469 - West Yorkshire Ale", "1728 - Scottish Ale", "1968 - London ESB Ale", "2565 - Kölsch", "1214 - Belgian Abbey", "1388 - Belgian Strong Ale", "1762 - Belgian Abbey II", "3056 - Bavarian Wheat Blend", "3068 - Weihenstephan Weizen", "3278 - Belgian Lambic Blend", "3333 - German Wheat", "3463 - Forbidden Fruit", "3522 - Belgian Ardennes", "3638 - Bavarian Wheat", "3711 - French Saison", "3724 - Belgian Saison", "3763 - Roeselare Ale Blend", "3787 - Trappist High Gravity", "3942 - Belgian Wheat", "3944 - Belgian Witbier", "2000 - Budvar Lager", "2001 - Urquell Lager", "2007 - Pilsen Lager", "2035 - American Lager", "2042 - Danish Lager", "2112 - California Lager", "2124 - Bohemian Lager", "2206 - Bavarian Lager", "2278 - Czech Pils", "2308 - Munich Lager", "2633 - Octoberfest Lager Blend", "5112 - Brettanomyces bruxellensis", "5335 - Lactobacillus", "5526 - Brettanomyces lambicus", "5733 - Pediococcus"},
8 | "malt": {"Black malt", "Caramel", "Carapils", "Chocolate", "Munich", "Caramel", "Carapils", "Chocolate malt", "Munich", "Pale", "Roasted barley", "Rye malt", "Special roast", "Victory", "Vienna", "Wheat mal"},
9 | "style": {"Light Lager", "Pilsner", "European Amber Lager", "Dark Lager", "Bock", "Light Hybrid Beer", "Amber Hybrid Beer", "English Pale Ale", "Scottish And Irish Ale", "Merican Ale", "English Brown Ale", "Porter", "Stout", "India Pale Ale", "German Wheat And Rye Beer", "Belgian And French Ale", "Sour Ale", "Belgian Strong Ale", "Strong Ale", "Fruit Beer", "Vegetable Beer", "Smoke-flavored", "Wood-aged Beer"},
10 | }
11 |
--------------------------------------------------------------------------------
/data/book.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | var Books = map[string][]string{
4 | "title": {
5 | "Anna Karenina",
6 | "Beloved",
7 | "Blindness",
8 | "Bostan",
9 | "Buddenbrooks",
10 | "Crime and Punishment",
11 | "Don Quijote De La Mancha",
12 | "Fairy tales",
13 | "Faust",
14 | "Gulliver's Travels",
15 | "Gypsy Ballads",
16 | "Hamlet",
17 | "Harry potter and the sorcerer's stone",
18 | "King Lear",
19 | "Leaves of Grass",
20 | "Lolita",
21 | "Madame Bovary",
22 | "Memoirs of Hadrian",
23 | "Metamorphoses",
24 | "Moby Dick",
25 | "Nineteen Eighty-Four",
26 | "Odyssey",
27 | "Oedipus the King",
28 | "One Hundred Years of Solitude",
29 | "One Thousand and One Nights",
30 | "Othello",
31 | "Pippi Longstocking",
32 | "Pride and Prejudice",
33 | "Romeo & Juliet",
34 | "Sherlock Holmes",
35 | "Sons and Lovers",
36 | "The Adventures of Huckleberry Finn",
37 | "The Book Of Job",
38 | "The Brothers Karamazov",
39 | "The Golden Notebook",
40 | "The Idiot",
41 | "The Old Man and the Sea",
42 | "The Stranger",
43 | "Things Fall Apart",
44 | "Ulysses",
45 | "War and Peace",
46 | "Wuthering Heights",
47 | "Zorba the Greek",
48 | },
49 | "author": {
50 | "Albert Camus",
51 | "Astrid Lindgren",
52 | "Charles Dickens",
53 | "D. H. Lawrence",
54 | "Edgar Allan Poe",
55 | "Emily Brontë",
56 | "Ernest Hemingway",
57 | "Franz Kafka",
58 | "Fyodor Dostoevsky",
59 | "George Orwell",
60 | "Hans Christian Andersen",
61 | "Homer",
62 | "James Joyce",
63 | "Jane Austen",
64 | "Johann Wolfgang von Goethe",
65 | "Jorge Luis Borges",
66 | "Joanne K. Rowling",
67 | "Leo Tolstoy",
68 | "Marcel Proust",
69 | "Mark Twain",
70 | "Paul Celan",
71 | "Salman Rushdie",
72 | "Sophocles",
73 | "Thomas Mann",
74 | "Toni Morrison",
75 | "Vladimir Nabokov",
76 | "William Faulkner",
77 | "William Shakespeare",
78 | "Yasunari Kawabata",
79 | },
80 | "genre": {
81 | "Adventure",
82 | "Comic",
83 | "Crime",
84 | "Erotic",
85 | "Fiction",
86 | "Fantasy",
87 | "Historical",
88 | "Horror",
89 | "Magic",
90 | "Mystery",
91 | "Philosophical",
92 | "Political",
93 | "Romance",
94 | "Saga",
95 | "Satire",
96 | "Science",
97 | "Speculative",
98 | "Thriller",
99 | "Urban",
100 | },
101 | }
--------------------------------------------------------------------------------
/data/computer.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Computer consists of computer information
4 | var Computer = map[string][]string{
5 | "linux_processor": {"i686", "x86_64"},
6 | "mac_processor": {"Intel", "PPC", "U; Intel", "U; PPC"},
7 | "windows_platform": {"Windows NT 6.2", "Windows NT 6.1", "Windows NT 6.0", "Windows NT 5.2", "Windows NT 5.1", "Windows NT 5.01", "Windows NT 5.0", "Windows NT 4.0", "Windows 98; Win 9x 4.90", "Windows 98", "Windows 95", "Windows CE"},
8 | }
9 |
--------------------------------------------------------------------------------
/data/currency.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Currency consists of currency information
4 | var Currency = map[string][]string{
5 | "short": {"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SPL", "SRD", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XCD", "XDR", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWD"},
6 | "long": {"United Arab Emirates Dirham", "Afghanistan Afghani", "Albania Lek", "Armenia Dram", "Netherlands Antilles Guilder", "Angola Kwanza", "Argentina Peso", "Australia Dollar", "Aruba Guilder", "Azerbaijan New Manat", "Bosnia and Herzegovina Convertible Marka", "Barbados Dollar", "Bangladesh Taka", "Bulgaria Lev", "Bahrain Dinar", "Burundi Franc", "Bermuda Dollar", "Brunei Darussalam Dollar", "Bolivia Boliviano", "Brazil Real", "Bahamas Dollar", "Bhutan Ngultrum", "Botswana Pula", "Belarus Ruble", "Belize Dollar", "Canada Dollar", "Congo/Kinshasa Franc", "Switzerland Franc", "Chile Peso", "China Yuan Renminbi", "Colombia Peso", "Costa Rica Colon", "Cuba Convertible Peso", "Cuba Peso", "Cape Verde Escudo", "Czech Republic Koruna", "Djibouti Franc", "Denmark Krone", "Dominican Republic Peso", "Algeria Dinar", "Egypt Pound", "Eritrea Nakfa", "Ethiopia Birr", "Euro Member Countries", "Fiji Dollar", "Falkland Islands (Malvinas) Pound", "United Kingdom Pound", "Georgia Lari", "Guernsey Pound", "Ghana Cedi", "Gibraltar Pound", "Gambia Dalasi", "Guinea Franc", "Guatemala Quetzal", "Guyana Dollar", "Hong Kong Dollar", "Honduras Lempira", "Croatia Kuna", "Haiti Gourde", "Hungary Forint", "Indonesia Rupiah", "Israel Shekel", "Isle of Man Pound", "India Rupee", "Iraq Dinar", "Iran Rial", "Iceland Krona", "Jersey Pound", "Jamaica Dollar", "Jordan Dinar", "Japan Yen", "Kenya Shilling", "Kyrgyzstan Som", "Cambodia Riel", "Comoros Franc", "Korea (North) Won", "Korea (South) Won", "Kuwait Dinar", "Cayman Islands Dollar", "Kazakhstan Tenge", "Laos Kip", "Lebanon Pound", "Sri Lanka Rupee", "Liberia Dollar", "Lesotho Loti", "Lithuania Litas", "Libya Dinar", "Morocco Dirham", "Moldova Leu", "Madagascar Ariary", "Macedonia Denar", "Myanmar (Burma) Kyat", "Mongolia Tughrik", "Macau Pataca", "Mauritania Ouguiya", "Mauritius Rupee", "Maldives (Maldive Islands) Rufiyaa", "Malawi Kwacha", "Mexico Peso", "Malaysia Ringgit", "Mozambique Metical", "Namibia Dollar", "Nigeria Naira", "Nicaragua Cordoba", "Norway Krone", "Nepal Rupee", "New Zealand Dollar", "Oman Rial", "Panama Balboa", "Peru Nuevo Sol", "Papua New Guinea Kina", "Philippines Peso", "Pakistan Rupee", "Poland Zloty", "Paraguay Guarani", "Qatar Riyal", "Romania New Leu", "Serbia Dinar", "Russia Ruble", "Rwanda Franc", "Saudi Arabia Riyal", "Solomon Islands Dollar", "Seychelles Rupee", "Sudan Pound", "Sweden Krona", "Singapore Dollar", "Saint Helena Pound", "Sierra Leone Leone", "Somalia Shilling", "Seborga Luigino", "Suriname Dollar", "São Tomé and Príncipe Dobra", "El Salvador Colon", "Syria Pound", "Swaziland Lilangeni", "Thailand Baht", "Tajikistan Somoni", "Turkmenistan Manat", "Tunisia Dinar", "Tonga Pa'anga", "Turkey Lira", "Trinidad and Tobago Dollar", "Tuvalu Dollar", "Taiwan New Dollar", "Tanzania Shilling", "Ukraine Hryvnia", "Uganda Shilling", "United States Dollar", "Uruguay Peso", "Uzbekistan Som", "Venezuela Bolivar", "Viet Nam Dong", "Vanuatu Vatu", "Samoa Tala", "Communauté Financière Africaine (BEAC) CFA Franc BEAC", "East Caribbean Dollar", "International Monetary Fund (IMF) Special Drawing Rights", "Communauté Financière Africaine (BCEAO) Franc", "Comptoirs Français du Pacifique (CFP) Franc", "Yemen Rial", "South Africa Rand", "Zambia Kwacha", "Zimbabwe Dollar"},
7 | }
8 |
--------------------------------------------------------------------------------
/data/data.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Data consists of the main set of fake information
4 | var Data = map[string]map[string][]string{
5 | "person": Person,
6 | "address": Address,
7 | "company": Company,
8 | "job": Job,
9 | "lorem": Lorem,
10 | "language": Languages,
11 | "internet": Internet,
12 | "file": Files,
13 | "color": Colors,
14 | "computer": Computer,
15 | "hipster": Hipster,
16 | "beer": Beer,
17 | "hacker": Hacker,
18 | "animal": Animal,
19 | "currency": Currency,
20 | "log_level": LogLevels,
21 | "timezone": TimeZone,
22 | "car": Car,
23 | "emoji": Emoji,
24 | "word": Word,
25 | "sentence": Sentence,
26 | "food": Food,
27 | "minecraft": Minecraft,
28 | "celebrity": Celebrity,
29 | "error": Error,
30 | "html": Html,
31 | "book": Books,
32 | "movie": Movies,
33 | "school": School,
34 | "song": Songs,
35 | "product": Product,
36 | "bank": Bank,
37 | }
38 |
39 | func List() map[string][]string {
40 | var list = make(map[string][]string)
41 |
42 | // Loop through the data and add the keys to the list
43 | for key := range Data {
44 | list[key] = []string{}
45 |
46 | // Loop through the sub data and add the keys to the list
47 | for subkey := range Data[key] {
48 | list[key] = append(list[key], subkey)
49 | }
50 | }
51 |
52 | return list
53 | }
54 |
55 | func Get(key string) map[string][]string {
56 | // Make sure the key exists, if not return an empty map
57 | if _, ok := Data[key]; !ok {
58 | return make(map[string][]string)
59 | }
60 |
61 | return Data[key]
62 | }
63 |
64 | func Set(key string, data map[string][]string) {
65 | Data[key] = data
66 | }
67 |
68 | func Remove(key string) {
69 | delete(Data, key)
70 | }
71 |
72 | func GetSubData(key, subkey string) []string {
73 | // Make sure the key exists, if not return an empty map
74 | if _, ok := Data[key]; !ok {
75 | return []string{}
76 | }
77 |
78 | return Data[key][subkey]
79 | }
80 |
81 | func SetSub(key, subkey string, data []string) {
82 | // Make sure the key exists, if not add it
83 | if _, ok := Data[key]; !ok {
84 | Data[key] = make(map[string][]string)
85 | }
86 |
87 | Data[key][subkey] = data
88 | }
89 |
90 | func RemoveSub(key, subkey string) {
91 | delete(Data[key], subkey)
92 | }
93 |
--------------------------------------------------------------------------------
/data/data_test.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 | "testing"
7 | )
8 |
9 | func TestList(t *testing.T) {
10 | // List data
11 | list := List()
12 |
13 | // Should get a filled list of map[string][]string
14 | if len(list) != len(Data) {
15 | t.Errorf("Expected %d items, got %d", len(Data), len(list))
16 | }
17 | }
18 |
19 | func ExampleGet() {
20 | // Get data
21 | data := Get("person")
22 |
23 | // Print the first name
24 | fmt.Println(data["prefix"])
25 |
26 | // Output:
27 | // [Mr. Mrs. Ms. Miss Dr.]
28 | }
29 |
30 | func ExampleGet_sub() {
31 | // Get data
32 | data := GetSubData("person", "prefix")
33 |
34 | // Print the first name
35 | fmt.Println(data[0])
36 |
37 | // Output:
38 | // Mr.
39 | }
40 |
41 | func TestGetData(t *testing.T) {
42 | // Get data
43 | data := Get("things")
44 |
45 | // Should get empty map
46 | if len(data) != 0 {
47 | t.Errorf("Expected 0 things, got %d", len(data))
48 | }
49 | }
50 |
51 | func TestGetSub(t *testing.T) {
52 | // Get data
53 | data := GetSubData("things", "cake")
54 |
55 | // Should get empty map
56 | if len(data) != 0 {
57 | t.Errorf("Expected 0 things, got %d", len(data))
58 | }
59 | }
60 |
61 | func ExampleSet() {
62 | // Add data
63 | Set("desserts", map[string][]string{
64 | "cake": {"chocolate", "vanilla"},
65 | "pie": {"apple", "pecan"},
66 | "ice cream": {"strawberry", "vanilla"},
67 | })
68 | }
69 |
70 | func ExampleSetSub() {
71 | // Add data
72 | SetSub("desserts", "cake", []string{"chocolate", "vanilla"})
73 | }
74 |
75 | func TestAddReplaceRemove(t *testing.T) {
76 | // Add data
77 | Set("desserts", map[string][]string{
78 | "cake": {"chocolate", "vanilla"},
79 | "pie": {"apple", "pecan"},
80 | "ice cream": {"strawberry", "vanilla"},
81 | })
82 |
83 | if len(Data["desserts"]) != 3 {
84 | t.Errorf("Expected 3 desserts, got %d", len(Data["desserts"]))
85 | }
86 | if len(Data["desserts"]["cake"]) != 2 {
87 | t.Errorf("Expected 2 cakes, got %d", len(Data["desserts"]["cake"]))
88 | }
89 |
90 | // Replace data
91 | Set("desserts", map[string][]string{
92 | "cake": {"carrot", "banana"},
93 | "pie": {"cherry", "peach"},
94 | "ice cream": {"caramel", "rainbow"},
95 | })
96 |
97 | if len(Data["desserts"]) != 3 {
98 | t.Errorf("Expected 3 desserts, got %d", len(Data["desserts"]))
99 | }
100 | if len(Data["desserts"]["cake"]) != 2 {
101 | t.Errorf("Expected 2 cakes, got %d", len(Data["desserts"]["cake"]))
102 | }
103 |
104 | // Remove data
105 | Remove("desserts")
106 |
107 | if len(Data["desserts"]) != 0 {
108 | t.Errorf("Expected 0 desserts, got %d", len(Data["desserts"]))
109 | }
110 | }
111 |
112 | func TestAddReplaceRemoveSub(t *testing.T) {
113 | // Add data
114 | SetSub("desserts", "cake", []string{"chocolate", "vanilla"})
115 |
116 | if len(Data["desserts"]["cake"]) != 2 {
117 | t.Errorf("Expected 2 cakes, got %d", len(Data["desserts"]["cake"]))
118 | }
119 |
120 | // Replace data
121 | SetSub("desserts", "cake", []string{"carrot", "banana"})
122 |
123 | if len(Data["desserts"]["cake"]) != 2 {
124 | t.Errorf("Expected 2 cakes, got %d", len(Data["desserts"]["cake"]))
125 | }
126 |
127 | // Remove data
128 | RemoveSub("desserts", "cake")
129 |
130 | if len(Data["desserts"]["cake"]) != 0 {
131 | t.Errorf("Expected 0 cakes, got %d", len(Data["desserts"]["cake"]))
132 | }
133 | }
134 |
135 | func TestTrailingSpaces(t *testing.T) {
136 | assertSpaces := func(selector, str string) {
137 | t.Helper()
138 | if str != strings.Trim(str, " ") {
139 | t.Errorf("In %s dataset: %q has leading or trailing space", selector, str)
140 | }
141 | }
142 |
143 | for dataKey, data := range Data {
144 | for key, values := range data {
145 | assertSpaces(dataKey, key)
146 | for _, v := range values {
147 | assertSpaces(dataKey, v)
148 | }
149 | }
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/data/errors.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | var Error = map[string][]string{
4 | "object": {
5 | "argument",
6 | "buffer",
7 | "connection",
8 | "database",
9 | "header",
10 | "hostname",
11 | "method",
12 | "object",
13 | "parameter",
14 | "pointer",
15 | "port",
16 | "protocol",
17 | "request",
18 | "response",
19 | "server",
20 | "service",
21 | "signature",
22 | "tag",
23 | "undefined",
24 | "url",
25 | "uri",
26 | "variable",
27 | },
28 | "generic": {
29 | "error",
30 | "syntax error",
31 | "requested {errorobject} is unavailable",
32 | "failed to {hackerverb} {errorobject}",
33 | "expected {errorobject} is undefined",
34 | "[object Object]",
35 | "no such variable",
36 | "{errorobject} not initialized",
37 | "variable assigned before declaration",
38 | },
39 | "database": {
40 | "sql error",
41 | "database connection error",
42 | "table does not exist",
43 | "unique key constraint",
44 | "table migration failed",
45 | "bad connection",
46 | "destination pointer is nil",
47 | },
48 | "grpc": {
49 | "connection refused",
50 | "connection closed",
51 | "connection is shut down",
52 | "client protocol error",
53 | },
54 | "http": {
55 | "cross-origin-resource-policy error",
56 | "feature not supported",
57 | "trailer header without chunked transfer encoding",
58 | "no multipart boundary param in Content-Type",
59 | "request Content-Type isn't multipart/form-data",
60 | "header too long",
61 | "entity body too short",
62 | "missing ContentLength in HEAD response",
63 | "named cookie not present",
64 | "invalid method",
65 | "connection has been hijacked",
66 | "request method or response status code does not allow body",
67 | "wrote more than the declared Content-Length",
68 | "{httpmethod} not allowed",
69 | },
70 | "http_client": { // 400s
71 | "bad request", // 400
72 | "unauthorized", // 401
73 | "payment required", // 402
74 | "forbidden", // 403
75 | "not found", // 404
76 | "method not allowed", // 405
77 | "not acceptable", // 406
78 | "proxy authentication required", // 407
79 | "request timeout", // 408
80 | "conflict", // 409
81 | "gone", // 410
82 | "length required", // 411
83 | "precondition failed", // 412
84 | "payload too large", // 413
85 | "URI too long", // 414
86 | "unsupported media type", // 415
87 | "range not satisfiable", // 416
88 | "expectation failed", // 417
89 | "im a teapot", // 418
90 | },
91 | "http_server": { // 500s
92 | "internal server error", // 500
93 | "not implemented", // 501
94 | "bad gateway", // 502
95 | "service unavailable", // 503
96 | "gateway timeout", // 504
97 | "http version not supported", // 505
98 | "variant also negotiates", // 506
99 | "insufficient storage", // 507
100 | "loop detected", // 508
101 | "not extended", // 510
102 | "network authentication required", // 511
103 | },
104 | "runtime": {
105 | "panic: runtime error: invalid memory address or nil pointer dereference",
106 | "address out of bounds",
107 | "undefined has no such property 'length'",
108 | "not enough arguments",
109 | "expected 2 arguments, got 3",
110 | },
111 | "validation": {
112 | "invalid format",
113 | "missing required field",
114 | "{inputname} is required",
115 | "{inputname} max length exceeded",
116 | "{inputname} must be at exactly 16 characters",
117 | "{inputname} must be at exactly 32 bytes",
118 | "failed to parse {inputname}",
119 | "date is in the past",
120 | "payment details cannot be verified",
121 | },
122 | }
123 |
--------------------------------------------------------------------------------
/data/hacker.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Hacker consists of random hacker phrases
4 | var Hacker = map[string][]string{
5 | "abbreviation": {"TCP", "HTTP", "SDD", "RAM", "GB", "CSS", "SSL", "AGP", "SQL", "FTP", "PCI", "AI", "ADP", "RSS", "XML", "EXE", "COM", "HDD", "THX", "SMTP", "SMS", "USB", "PNG", "SAS", "IB", "SCSI", "JSON", "XSS", "JBOD"},
6 | "adjective": {"auxiliary", "primary", "back-end", "digital", "open-source", "virtual", "cross-platform", "redundant", "online", "haptic", "multi-byte", "bluetooth", "wireless", "1080p", "neural", "optical", "solid state", "mobile"},
7 | "noun": {"driver", "protocol", "bandwidth", "panel", "microchip", "program", "port", "card", "array", "interface", "system", "sensor", "firewall", "hard drive", "pixel", "alarm", "feed", "monitor", "application", "transmitter", "bus", "circuit", "capacitor", "matrix"},
8 | "verb": {"back up", "bypass", "hack", "override", "compress", "copy", "navigate", "index", "connect", "generate", "quantify", "calculate", "synthesize", "input", "transmit", "program", "reboot", "parse", "read", "write", "load", "render", "validate", "verify", "sign", "decrypt", "encrypt", "construct", "deconstruct", "compile", "transpile", "bundle", "lock", "unlock", "buffer", "format"},
9 | "ingverb": {"backing up", "bypassing", "hacking", "overriding", "compressing", "copying", "navigating", "indexing", "connecting", "generating", "quantifying", "calculating", "synthesizing", "transmitting", "programming", "parsing"},
10 | "phrase": {
11 | "If we {hackerverb} the {hackernoun}, we can get to the {hackerabbreviation} {hackernoun} through the {hackeradjective} {hackerabbreviation} {hackernoun}!",
12 | "We need to {hackerverb} the {hackeradjective} {hackerabbreviation} {hackernoun}!",
13 | "Try to {hackerverb} the {hackerabbreviation} {hackernoun}, maybe it will {hackerverb} the {hackeradjective} {hackernoun}!",
14 | "You can't {hackerverb} the {hackernoun} without {hackeringverb} the {hackeradjective} {hackerabbreviation} {hackernoun}!",
15 | "Use the {hackeradjective} {hackerabbreviation} {hackernoun}, then you can {hackerverb} the {hackeradjective} {hackernoun}!",
16 | "The {hackerabbreviation} {hackernoun} is down, {hackerverb} the {hackeradjective} {hackernoun} so we can {hackerverb} the {hackerabbreviation} {hackernoun}!",
17 | "{hackeringverb} the {hackernoun} won't do anything, we need to {hackerverb} the {hackeradjective} {hackerabbreviation} {hackernoun}!",
18 | "I'll {hackerverb} the {hackeradjective} {hackerabbreviation} {hackernoun}, that should {hackerverb} the {hackerabbreviation} {hackernoun}!",
19 | },
20 | }
21 |
--------------------------------------------------------------------------------
/data/hipster.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Hipster consists of random hipster words
4 | var Hipster = map[string][]string{
5 | "word": {"Wes Anderson", "chicharrones", "narwhal", "food truck", "marfa", "aesthetic", "keytar", "art party", "sustainable", "forage", "mlkshk", "gentrify", "locavore", "swag", "hoodie", "microdosing", "VHS", "before they sold out", "pabst", "plaid", "Thundercats", "freegan", "scenester", "hella", "occupy", "truffaut", "raw denim", "beard", "post-ironic", "photo booth", "twee", "90's", "pitchfork", "cray", "cornhole", "kale chips", "pour-over", "yr", "five dollar toast", "kombucha", "you probably haven't heard of them", "mustache", "fixie", "try-hard", "franzen", "kitsch", "austin", "stumptown", "keffiyeh", "whatever", "tumblr", "DIY", "shoreditch", "biodiesel", "vegan", "pop-up", "banjo", "kogi", "cold-pressed", "letterpress", "chambray", "butcher", "synth", "trust fund", "hammock", "farm-to-table", "intelligentsia", "loko", "ugh", "offal", "poutine", "gastropub", "Godard", "jean shorts", "sriracha", "dreamcatcher", "leggings", "fashion axe", "church-key", "meggings", "tote bag", "disrupt", "readymade", "helvetica", "flannel", "meh", "roof", "hashtag", "knausgaard", "cronut", "schlitz", "green juice", "waistcoat", "normcore", "viral", "ethical", "actually", "fingerstache", "humblebrag", "deep v", "wayfarers", "tacos", "taxidermy", "selvage", "put a bird on it", "ramps", "portland", "retro", "kickstarter", "bushwick", "brunch", "distillery", "migas", "flexitarian", "XOXO", "small batch", "messenger bag", "heirloom", "tofu", "bicycle rights", "bespoke", "salvia", "wolf", "selfies", "echo", "park", "listicle", "craft beer", "chartreuse", "sartorial", "pinterest", "mumblecore", "kinfolk", "vinyl", "etsy", "umami", "8-bit", "polaroid", "banh mi", "crucifix", "bitters", "brooklyn", "PBR&B", "drinking", "vinegar", "squid", "tattooed", "skateboard", "vice", "authentic", "literally", "lomo", "celiac", "health", "goth", "artisan", "chillwave", "blue bottle", "pickled", "next level", "neutra", "organic", "Yuccie", "paleo", "blog", "single-origin coffee", "seitan", "street", "gluten-free", "mixtape", "venmo", "irony", "everyday", "carry", "slow-carb", "3 wolf moon", "direct trade", "lo-fi", "tousled", "tilde", "semiotics", "cred", "chia", "master", "cleanse", "ennui", "quinoa", "pug", "iPhone", "fanny pack", "cliche", "cardigan", "asymmetrical", "meditation", "YOLO", "typewriter", "pork belly", "shabby chic", "+1", "lumbersexual", "williamsburg"},
6 | }
7 |
--------------------------------------------------------------------------------
/data/html.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Html consists of various html information
4 | var Html = map[string][]string{
5 | "svg": {"rect", "circle", "ellipse", "line", "polyline", "polygon"},
6 | "input_name": {"title", "first_name", "last_name", "suffix", "address", "postal_code", "city", "state", "country", "date_of_birth", "card_number", "description", "message", "status"},
7 | }
8 |
--------------------------------------------------------------------------------
/data/internet.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Internet consists of various internet information
4 | var Internet = map[string][]string{
5 | "browser": {"firefox", "chrome", "internetExplorer", "opera", "safari"},
6 | "domain_suffix": {"com", "biz", "info", "name", "net", "org", "io"},
7 | "http_method": {"HEAD", "GET", "POST", "PUT", "PATCH", "DELETE"},
8 | "http_version": {"HTTP/1.0", "HTTP/1.1", "HTTP/2.0"},
9 | "http_status_simple": {"200", "301", "302", "400", "404", "500"},
10 | "http_status_general": {"100", "200", "201", "203", "204", "205", "301", "302", "304", "400", "401", "403", "404", "405", "406", "416", "500", "501", "502", "503", "504"},
11 | }
12 |
--------------------------------------------------------------------------------
/data/job.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Job consists of job data
4 | var Job = map[string][]string{
5 | "title": {"Administrator", "Agent", "Analyst", "Architect", "Assistant", "Associate", "Consultant", "Coordinator", "Designer", "Developer", "Director", "Engineer", "Executive", "Facilitator", "Liaison", "Manager", "Officer", "Orchestrator", "Planner", "Producer", "Representative", "Specialist", "Strategist", "Supervisor", "Technician"},
6 | "descriptor": {"Central", "Chief", "Corporate", "Customer", "Direct", "District", "Dynamic", "Dynamic", "Forward", "Future", "Global", "Human", "Internal", "International", "Investor", "Lead", "Legacy", "National", "Principal", "Product", "Regional", "Senior"},
7 | "level": {"Accountability", "Accounts", "Applications", "Assurance", "Brand", "Branding", "Communications", "Configuration", "Creative", "Data", "Directives", "Division", "Factors", "Functionality", "Group", "Identity", "Implementation", "Infrastructure", "Integration", "Interactions", "Intranet", "Marketing", "Markets", "Metrics", "Mobility", "Operations", "Optimization", "Paradigm", "Program", "Quality", "Research", "Response", "Security", "Solutions", "Tactics", "Usability", "Web"},
8 | }
9 |
--------------------------------------------------------------------------------
/data/log_level.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // LogLevels consists of log levels for several types
4 | var LogLevels = map[string][]string{
5 | "general": {"error", "warning", "info", "fatal", "trace", "debug"},
6 | "syslog": {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"},
7 | "apache": {"emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", "trace1-8"},
8 | }
9 |
--------------------------------------------------------------------------------
/data/lorem.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Lorem consists of lorem ipsum information
4 | var Lorem = map[string][]string{
5 | "word": {"alias", "consequatur", "aut", "perferendis", "sit", "voluptatem", "accusantium", "doloremque", "aperiam", "eaque", "ipsa", "quae", "ab", "illo", "inventore", "veritatis", "et", "quasi", "architecto", "beatae", "vitae", "dicta", "sunt", "explicabo", "aspernatur", "aut", "odit", "aut", "fugit", "sed", "quia", "consequuntur", "magni", "dolores", "eos", "qui", "ratione", "voluptatem", "sequi", "nesciunt", "neque", "dolorem", "ipsum", "quia", "dolor", "sit", "amet", "consectetur", "adipisci", "velit", "sed", "quia", "non", "numquam", "eius", "modi", "tempora", "incidunt", "ut", "labore", "et", "dolore", "magnam", "aliquam", "quaerat", "voluptatem", "ut", "enim", "ad", "minima", "veniam", "quis", "nostrum", "exercitationem", "ullam", "corporis", "nemo", "enim", "ipsam", "voluptatem", "quia", "voluptas", "sit", "suscipit", "laboriosam", "nisi", "ut", "aliquid", "ex", "ea", "commodi", "consequatur", "quis", "autem", "vel", "eum", "iure", "reprehenderit", "qui", "in", "ea", "voluptate", "velit", "esse", "quam", "nihil", "molestiae", "et", "iusto", "odio", "dignissimos", "ducimus", "qui", "blanditiis", "praesentium", "laudantium", "totam", "rem", "voluptatum", "deleniti", "atque", "corrupti", "quos", "dolores", "et", "quas", "molestias", "excepturi", "sint", "occaecati", "cupiditate", "non", "provident", "sed", "ut", "perspiciatis", "unde", "omnis", "iste", "natus", "error", "similique", "sunt", "in", "culpa", "qui", "officia", "deserunt", "mollitia", "animi", "id", "est", "laborum", "et", "dolorum", "fuga", "et", "harum", "quidem", "rerum", "facilis", "est", "et", "expedita", "distinctio", "nam", "libero", "tempore", "cum", "soluta", "nobis", "est", "eligendi", "optio", "cumque", "nihil", "impedit", "quo", "porro", "quisquam", "est", "qui", "minus", "id", "quod", "maxime", "placeat", "facere", "possimus", "omnis", "voluptas", "assumenda", "est", "omnis", "dolor", "repellendus", "temporibus", "autem", "quibusdam", "et", "aut", "consequatur", "vel", "illum", "qui", "dolorem", "eum", "fugiat", "quo", "voluptas", "nulla", "pariatur", "at", "vero", "eos", "et", "accusamus", "officiis", "debitis", "aut", "rerum", "necessitatibus", "saepe", "eveniet", "ut", "et", "voluptates", "repudiandae", "sint", "et", "molestiae", "non", "recusandae", "itaque", "earum", "rerum", "hic", "tenetur", "a", "sapiente", "delectus", "ut", "aut", "reiciendis", "voluptatibus", "maiores", "doloribus", "asperiores", "repellat"},
6 | }
7 |
--------------------------------------------------------------------------------
/data/minecraft.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // Minecraft consists of various minecraft items
4 | var Minecraft = map[string][]string{
5 | "ore": {"coal", "copper", "iron", "gold", "redstone", "lapis", "diamond", "emerald"},
6 | "wood": {"oak", "spruce", "birch", "jungle", "acacia", "dark oak"},
7 | "armortier": {"leather", "chainmail", "iron", "gold", "diamond", "netherite"},
8 | "armorpart": {"helmet", "chestplate", "leggings", "boots"},
9 | "weapon": {"sword", "bow", "arrow", "trident", "shield"},
10 | "tool": {"pickaxe", "axe", "shovel", "hoe", "fishing rod"},
11 | "dye": {"white", "orange", "magenta", "light blue", "yellow", "lime", "pink", "gray", "light gray", "cyan", "purple", "blue", "brown", "green", "red", "black"},
12 | "food": {"apple", "baked potato", "beetroot", "beetroot soup", "bread", "cake", "carrot", "chorus fruit", "cooked chicken", "cooked cod", "cooked mutton", "cooked salmon", "cookie", "enchanted golden apple", "golden apple", "glow berry", "golden carrot", "honey bottle", "melon slice", "mushroom stew", "poisonous potato", "potato", "pufferfish", "pumpkin pie", "rabbit stew", "raw beef", "raw chicken", "raw cod", "raw mutton", "raw porkchop", "raw rabbit", "raw salmon", "rotten flesh", "spider eye", "steak", "suspicous stew", "sweet berry", "tropical fish"},
13 | "animal": {"chicken", "cow", "pig", "rabbit", "sheep", "wolf"},
14 | "villagerjob": {"armourer", "butcher", "carpenter", "cleric", "farmer", "fisherman", "fletcher", "leatherworker", "librarian", "mason", "nitwit", "shepherd", "toolsmith", "weaponsmith"},
15 | "villagerstation": {"composter", "smoker", "barrel", "loom", "blast furnace", "brewing stand", "cauldron", "fletching table", "cartography table", "lectern", "smithing table", "stonecutter", "grindstone"},
16 | "villagerlevel": {"novice", "apprentice", "journeyman", "expert", "master"},
17 | "mobpassive": {"axolotl", "bat", "cat", "chicken", "cod", "cow", "donkey", "fox", "glow squid", "horse", "mooshroom", "mule", "ocelot", "parrot", "pig", "pufferfish", "rabbit", "salmon", "sheep", "skeleton horse", "snow golem", "squid", "strider", "tropical fish", "turtle", "villager", "wandering trader"},
18 | "mobneutral": {"bee", "cave spider", "dolphin", "enderman", "goat", "iron golem", "llama", "panda", "piglin", "polar bear", "spider", "trader llama", "wolf", "zombified piglin"},
19 | "mobhostile": {"blaze", "chicken jockey", "creeper", "drowned", "elder guardian", "endermite", "evoker", "ghast", "guardian", "hoglin phantom", "husk", "magma cube", "phantom", "piglin brute", "pillager", "ravager", "shulker", "silverfish", "skeleton", "skeleton horseman", "slime", "spider jockey", "stray", "vex", "vindicator", "witch", "wither skeleton", "zoglin", "zombie", "zombie villager"},
20 | "mobboss": {"ender dragon", "wither"},
21 | "biome": {"plain", "forest", "jungle", "mountain", "desert", "taiga", "snowy tundra", "ice spike", "swamp", "savannah", "badlands", "beach", "stone shore", "river", "ocean", "mushroom island", "the nether", "the end"},
22 | "weather": {"clear", "rain", "thunder"},
23 | }
24 |
--------------------------------------------------------------------------------
/data/movie.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // From IMDB - Top 250 Movies subset to 100
4 | var Movies = map[string][]string{
5 | "name": {
6 | "12 Years a Slave",
7 | "1917",
8 | "2001: A Space Odyssey",
9 | "3 Idiots",
10 | "A Beautiful Mind",
11 | "A Clockwork Orange",
12 | "Alien",
13 | "American Beauty",
14 | "American History X",
15 | "Apocalypse Now",
16 | "Avengers: Infinity War",
17 | "Back to the Future",
18 | "Batman Begins",
19 | "Ben-Hur",
20 | "Blade Runner",
21 | "Casablanca",
22 | "Casino",
23 | "Catch Me If You Can",
24 | "Das Leben der Anderen",
25 | "Dead Poets Society",
26 | "Die Hard",
27 | "Django Unchained",
28 | "Fight Club",
29 | "Finding Nemo",
30 | "Forrest Gump",
31 | "Full Metal Jacket",
32 | "Gandhi",
33 | "Gladiator",
34 | "Gone with the Wind",
35 | "Good Will Hunting",
36 | "Goodfellas",
37 | "Green Book",
38 | "Groundhog Day",
39 | "Harry Potter and the Deathly Hallows - Part 2",
40 | "Heat",
41 | "Inception",
42 | "Indiana Jones and the Last Crusade",
43 | "Inglourious Basterds",
44 | "Interstellar",
45 | "Into the Wild",
46 | "Intouchables",
47 | "Joker",
48 | "Judgment at Nuremberg",
49 | "Jurassic Park",
50 | "Kill Bill: Vol. 1",
51 | "L.A. Confidential",
52 | "La vita è bella",
53 | "Lock, Stock and Two Smoking Barrels",
54 | "Léon",
55 | "Mad Max: Fury Road",
56 | "Memento",
57 | "Million Dollar Baby",
58 | "Monsters, Inc.",
59 | "Monty Python and the Holy Grail",
60 | "No Country for Old Men",
61 | "Once Upon a Time in America",
62 | "One Flew Over the Cuckoo's Nest",
63 | "Pirates of the Caribbean: The Curse of the Black Pearl",
64 | "Platoon",
65 | "Prisoners",
66 | "Psycho",
67 | "Pulp Fiction",
68 | "Raiders of the Lost Ark",
69 | "Ratatouille",
70 | "Reservoir Dogs",
71 | "Rocky",
72 | "Saving Private Ryan",
73 | "Scarface",
74 | "Schindler's List",
75 | "Se7en",
76 | "Sherlock Jr.",
77 | "Shutter Island",
78 | "Snatch",
79 | "Spider-Man: No Way Home",
80 | "Star Wars: Episode VI - Return of the Jedi",
81 | "Taxi Driver",
82 | "Terminator 2: Judgment Day",
83 | "The Big Lebowski",
84 | "The Dark Knight",
85 | "The Departed",
86 | "The Empire Strikes Back",
87 | "The Godfather",
88 | "The Green Mile",
89 | "The Lion King",
90 | "The Lord of the Rings: The Fellowship of the Ring",
91 | "The Matrix",
92 | "The Pianist",
93 | "The Prestige",
94 | "The Shawshank Redemption",
95 | "The Terminator",
96 | "The Usual Suspects",
97 | "The Wolf of Wall Street",
98 | "Top Gun: Maverick",
99 | "Toy Story",
100 | "Unforgiven",
101 | "Up",
102 | "V for Vendetta",
103 | "WALL·E",
104 | "Warrior",
105 | "Whiplash",
106 | },
107 | "genre": {
108 | "Action",
109 | "Adventure",
110 | "Animation",
111 | "Biography",
112 | "Comedy",
113 | "Crime",
114 | "Drama",
115 | "Family",
116 | "Fantasy",
117 | "Film-Noir",
118 | "History",
119 | "Horror",
120 | "Music",
121 | "Musical",
122 | "Mystery",
123 | "Romance",
124 | "Sci-Fi",
125 | "Sport",
126 | "Thriller",
127 | "War",
128 | "Western",
129 | },
130 | }
131 |
--------------------------------------------------------------------------------
/data/school.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | // School type and names
4 | var School = map[string][]string{
5 | "type": {"Elementary School", "Middle School", "University", "High School", "Kindergarten", "Academy", "College", "Institute"},
6 | "isPrivate": {"Private", "State"},
7 | "name": {"Maplewood",
8 | "Pineville",
9 | "Riverside",
10 | "Willowbrook",
11 | "Crestwood",
12 | "Sunset",
13 | "Greenfield",
14 | "Oakwood",
15 | "Willowbrook",
16 | "Hawthorn",
17 | "Brookside",
18 | "Pleasant View",
19 | "Crescent Valley",
20 | "Sycamore",
21 | "Springfield",
22 | "Meadowbrook",
23 | "Greenwood",
24 | "Riverbend",
25 | "Valley Forge",
26 | "Ridgeview",
27 | "Cottonwood",
28 | "Cedarwood",
29 | "Golden Oak",
30 | "Stonebridge",
31 | "Harborview",
32 | "Windsor",
33 | "Northbrook",
34 | "Sunset",
35 | "Redwood Valley",
36 | "Liberty",
37 | "Washington Central",
38 | "Franklin",
39 | "Jefferson",
40 | "Lincoln Park",
41 | "Madison",
42 | "Roosevelt",
43 | "Westwood",
44 | "Central Lakeside",
45 | "Fairview",
46 | "Heritage Hills",
47 | "Kingsbridge",
48 | "Harrisonville",
49 | "Valley View",
50 | "Hillside",
51 | "Northridge",
52 | "Brooklyn Heights",
53 | "Oakridge",
54 | "Countryside",
55 | },
56 | }
--------------------------------------------------------------------------------
/data/word_test.go:
--------------------------------------------------------------------------------
1 | package data
2 |
3 | import (
4 | "strings"
5 | "testing"
6 | )
7 |
8 | // Loop through the map keys and loop through the values of each key
9 | // to check for space before or after each string
10 | func TestCheckWordForSpaces(t *testing.T) {
11 | for key, values := range Word {
12 | // Loop through the values
13 | for _, value := range values {
14 | // Check if value starts with a space
15 | if strings.HasPrefix(value, " ") {
16 | t.Errorf("category %s value %s starts with a space", key, value)
17 | }
18 |
19 | // Check if value ends with a space
20 | if strings.HasSuffix(value, " ") {
21 | t.Errorf("category %s value %s starts with a space", key, value)
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/doc.go:
--------------------------------------------------------------------------------
1 | /*
2 | Package gofakeit provides a set of functions that generate random data
3 | */
4 | package gofakeit
5 |
--------------------------------------------------------------------------------
/emoji.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | // Emoji will return a random fun emoji
4 | func Emoji() string { return emoji(GlobalFaker) }
5 |
6 | // Emoji will return a random fun emoji
7 | func (f *Faker) Emoji() string { return emoji(f) }
8 |
9 | func emoji(f *Faker) string { return getRandValue(f, []string{"emoji", "emoji"}) }
10 |
11 | // EmojiDescription will return a random fun emoji description
12 | func EmojiDescription() string { return emojiDescription(GlobalFaker) }
13 |
14 | // EmojiDescription will return a random fun emoji description
15 | func (f *Faker) EmojiDescription() string { return emojiDescription(f) }
16 |
17 | func emojiDescription(f *Faker) string { return getRandValue(f, []string{"emoji", "description"}) }
18 |
19 | // EmojiCategory will return a random fun emoji category
20 | func EmojiCategory() string { return emojiCategory(GlobalFaker) }
21 |
22 | // EmojiCategory will return a random fun emoji category
23 | func (f *Faker) EmojiCategory() string { return emojiCategory(f) }
24 |
25 | func emojiCategory(f *Faker) string { return getRandValue(f, []string{"emoji", "category"}) }
26 |
27 | // EmojiAlias will return a random fun emoji alias
28 | func EmojiAlias() string { return emojiAlias(GlobalFaker) }
29 |
30 | // EmojiAlias will return a random fun emoji alias
31 | func (f *Faker) EmojiAlias() string { return emojiAlias(f) }
32 |
33 | func emojiAlias(f *Faker) string { return getRandValue(f, []string{"emoji", "alias"}) }
34 |
35 | // EmojiTag will return a random fun emoji tag
36 | func EmojiTag() string { return emojiTag(GlobalFaker) }
37 |
38 | // EmojiTag will return a random fun emoji tag
39 | func (f *Faker) EmojiTag() string { return emojiTag(f) }
40 |
41 | func emojiTag(f *Faker) string { return getRandValue(f, []string{"emoji", "tag"}) }
42 |
43 | func addEmojiLookup() {
44 | AddFuncLookup("emoji", Info{
45 | Display: "Emoji",
46 | Category: "emoji",
47 | Description: "Digital symbol expressing feelings or ideas in text messages and online chats",
48 | Example: "🤣",
49 | Output: "string",
50 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
51 | return emoji(f), nil
52 | },
53 | })
54 |
55 | AddFuncLookup("emojidescription", Info{
56 | Display: "Emoji Description",
57 | Category: "emoji",
58 | Description: "Brief explanation of the meaning or emotion conveyed by an emoji",
59 | Example: "face vomiting",
60 | Output: "string",
61 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
62 | return emojiDescription(f), nil
63 | },
64 | })
65 |
66 | AddFuncLookup("emojicategory", Info{
67 | Display: "Emoji Category",
68 | Category: "emoji",
69 | Description: "Group or classification of emojis based on their common theme or use, like 'smileys' or 'animals'",
70 | Example: "Smileys & Emotion",
71 | Output: "string",
72 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
73 | return emojiCategory(f), nil
74 | },
75 | })
76 |
77 | AddFuncLookup("emojialias", Info{
78 | Display: "Emoji Alias",
79 | Category: "emoji",
80 | Description: "Alternative name or keyword used to represent a specific emoji in text or code",
81 | Example: "smile",
82 | Output: "string",
83 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
84 | return emojiAlias(f), nil
85 | },
86 | })
87 |
88 | AddFuncLookup("emojitag", Info{
89 | Display: "Emoji Tag",
90 | Category: "emoji",
91 | Description: "Label or keyword associated with an emoji to categorize or search for it easily",
92 | Example: "happy",
93 | Output: "string",
94 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
95 | return emojiTag(f), nil
96 | },
97 | })
98 | }
99 |
--------------------------------------------------------------------------------
/emoji_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleEmoji() {
9 | Seed(11)
10 | fmt.Println(Emoji())
11 |
12 | // Output: 🇫🇴
13 | }
14 |
15 | func ExampleFaker_Emoji() {
16 | f := New(11)
17 | fmt.Println(f.Emoji())
18 |
19 | // Output: 🇫🇴
20 | }
21 |
22 | func BenchmarkEmoji(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Emoji()
25 | }
26 | }
27 |
28 | func ExampleEmojiDescription() {
29 | Seed(11)
30 | fmt.Println(EmojiDescription())
31 |
32 | // Output: flag: European Union
33 | }
34 |
35 | func ExampleFaker_EmojiDescription() {
36 | f := New(11)
37 | fmt.Println(f.EmojiDescription())
38 |
39 | // Output: flag: European Union
40 | }
41 |
42 | func BenchmarkEmojiDescription(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | EmojiDescription()
45 | }
46 | }
47 |
48 | func ExampleEmojiCategory() {
49 | Seed(11)
50 | fmt.Println(EmojiCategory())
51 |
52 | // Output: Flags
53 | }
54 |
55 | func ExampleFaker_EmojiCategory() {
56 | f := New(11)
57 | fmt.Println(f.EmojiCategory())
58 |
59 | // Output: Flags
60 | }
61 |
62 | func BenchmarkEmojiCategory(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | EmojiCategory()
65 | }
66 | }
67 |
68 | func ExampleEmojiAlias() {
69 | Seed(11)
70 | fmt.Println(EmojiAlias())
71 |
72 | // Output: eritrea
73 | }
74 |
75 | func ExampleFaker_EmojiAlias() {
76 | f := New(11)
77 | fmt.Println(f.EmojiAlias())
78 |
79 | // Output: eritrea
80 | }
81 |
82 | func BenchmarkEmojiAlias(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | EmojiAlias()
85 | }
86 | }
87 |
88 | func ExampleEmojiTag() {
89 | Seed(11)
90 | fmt.Println(EmojiTag())
91 |
92 | // Output: toilet
93 | }
94 |
95 | func ExampleFaker_EmojiTag() {
96 | f := New(11)
97 | fmt.Println(f.EmojiTag())
98 |
99 | // Output: toilet
100 | }
101 |
102 | func BenchmarkEmojiTag(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | EmojiTag()
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/error_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleError() {
9 | Seed(11)
10 | fmt.Println(Error())
11 |
12 | // Output: variable assigned before declaration
13 | }
14 |
15 | func ExampleFaker_Error() {
16 | f := New(11)
17 | fmt.Println(f.Error())
18 |
19 | // Output: variable assigned before declaration
20 | }
21 |
22 | func BenchmarkError(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Error()
25 | }
26 | }
27 |
28 | func ExampleErrorObject() {
29 | Seed(11)
30 | fmt.Println(ErrorObject())
31 |
32 | // Output: url
33 | }
34 |
35 | func ExampleFaker_ErrorObject() {
36 | f := New(11)
37 | fmt.Println(f.ErrorObject())
38 |
39 | // Output: url
40 | }
41 |
42 | func BenchmarkErrorObject(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | ErrorObject()
45 | }
46 | }
47 |
48 | func ExampleErrorDatabase() {
49 | Seed(11)
50 | fmt.Println(ErrorDatabase())
51 |
52 | // Output: destination pointer is nil
53 | }
54 |
55 | func ExampleFaker_ErrorDatabase() {
56 | f := New(11)
57 | fmt.Println(f.ErrorDatabase())
58 |
59 | // Output: destination pointer is nil
60 | }
61 |
62 | func BenchmarkErrorDatabase(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | ErrorDatabase()
65 | }
66 | }
67 |
68 | func ExampleErrorGRPC() {
69 | Seed(11)
70 | fmt.Println(ErrorGRPC())
71 |
72 | // Output: connection refused
73 | }
74 |
75 | func ExampleFaker_ErrorGRPC() {
76 | f := New(11)
77 | fmt.Println(f.ErrorGRPC())
78 |
79 | // Output: connection refused
80 | }
81 |
82 | func BenchmarkErrorGRPC(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | ErrorGRPC()
85 | }
86 | }
87 |
88 | func ExampleErrorHTTP() {
89 | Seed(11)
90 | fmt.Println(ErrorHTTP())
91 |
92 | // Output: wrote more than the declared Content-Length
93 | }
94 |
95 | func ExampleFaker_ErrorHTTP() {
96 | f := New(11)
97 | fmt.Println(f.ErrorHTTP())
98 |
99 | // Output: wrote more than the declared Content-Length
100 | }
101 |
102 | func BenchmarkErrorHTTP(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | ErrorHTTP()
105 | }
106 | }
107 |
108 | func ExampleErrorHTTPClient() {
109 | Seed(11)
110 | fmt.Println(ErrorHTTPClient())
111 |
112 | // Output: expectation failed
113 | }
114 |
115 | func ExampleFaker_ErrorHTTPClient() {
116 | f := New(11)
117 | fmt.Println(f.ErrorHTTPClient())
118 |
119 | // Output: expectation failed
120 | }
121 |
122 | func BenchmarkErrorHTTPClient(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | ErrorHTTPClient()
125 | }
126 | }
127 |
128 | func ExampleErrorHTTPServer() {
129 | Seed(11)
130 | fmt.Println(ErrorHTTPServer())
131 |
132 | // Output: not extended
133 | }
134 |
135 | func ExampleFaker_ErrorHTTPServer() {
136 | f := New(11)
137 | fmt.Println(f.ErrorHTTPServer())
138 |
139 | // Output: not extended
140 | }
141 |
142 | func BenchmarkErrorHTTPServer(b *testing.B) {
143 | for i := 0; i < b.N; i++ {
144 | ErrorHTTPServer()
145 | }
146 | }
147 |
148 | func ExampleErrorRuntime() {
149 | Seed(11)
150 | fmt.Println(ErrorRuntime())
151 |
152 | // Output: expected 2 arguments, got 3
153 | }
154 |
155 | func ExampleFaker_ErrorRuntime() {
156 | f := New(11)
157 | fmt.Println(f.ErrorRuntime())
158 |
159 | // Output: expected 2 arguments, got 3
160 | }
161 |
162 | func BenchmarkErrorRuntime(b *testing.B) {
163 | for i := 0; i < b.N; i++ {
164 | ErrorRuntime()
165 | }
166 | }
167 |
168 | func ExampleErrorValidation() {
169 | Seed(11)
170 | fmt.Println(ErrorValidation())
171 |
172 | // Output: payment details cannot be verified
173 | }
174 |
175 | func ExampleFaker_ErrorValidation() {
176 | f := New(11)
177 | fmt.Println(f.ErrorValidation())
178 |
179 | // Output: payment details cannot be verified
180 | }
181 |
182 | func BenchmarkErrorValidation(b *testing.B) {
183 | for i := 0; i < b.N; i++ {
184 | ErrorValidation()
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/fakeable.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "errors"
5 | "fmt"
6 | "reflect"
7 | )
8 |
9 | // Fakeable is an interface that can be implemented by a type to provide a custom fake value.
10 | type Fakeable interface {
11 | // Fake returns a fake value for the type.
12 | Fake(faker *Faker) (any, error)
13 | }
14 |
15 | func isFakeable(t reflect.Type) bool {
16 | fakeableTyp := reflect.TypeOf((*Fakeable)(nil)).Elem()
17 |
18 | return t.Implements(fakeableTyp) || reflect.PointerTo(t).Implements(fakeableTyp)
19 | }
20 |
21 | func callFake(faker *Faker, v reflect.Value, possibleKinds ...reflect.Kind) (any, error) {
22 | f, ok := v.Addr().Interface().(Fakeable)
23 | if !ok {
24 | return nil, errors.New("not a Fakeable type")
25 | }
26 |
27 | fakedValue, err := f.Fake(faker)
28 | if err != nil {
29 | return nil, fmt.Errorf("error calling Fake: %w", err)
30 | }
31 | k := reflect.TypeOf(fakedValue).Kind()
32 | if !containsKind(possibleKinds, k) {
33 | return nil, fmt.Errorf("returned value kind %q is not amongst the valid ones: %v", k, possibleKinds)
34 | }
35 |
36 | switch k {
37 | case reflect.String:
38 | return reflect.ValueOf(fakedValue).String(), nil
39 | case reflect.Bool:
40 | return reflect.ValueOf(fakedValue).Bool(), nil
41 | case reflect.Int:
42 | return int(reflect.ValueOf(fakedValue).Int()), nil
43 | case reflect.Int8:
44 | return int8(reflect.ValueOf(fakedValue).Int()), nil
45 | case reflect.Int16:
46 | return int16(reflect.ValueOf(fakedValue).Int()), nil
47 | case reflect.Int32:
48 | return int32(reflect.ValueOf(fakedValue).Int()), nil
49 | case reflect.Int64:
50 | return int64(reflect.ValueOf(fakedValue).Int()), nil
51 | case reflect.Uint:
52 | return uint(reflect.ValueOf(fakedValue).Uint()), nil
53 | case reflect.Uint8:
54 | return uint8(reflect.ValueOf(fakedValue).Uint()), nil
55 | case reflect.Uint16:
56 | return uint16(reflect.ValueOf(fakedValue).Uint()), nil
57 | case reflect.Uint32:
58 | return uint32(reflect.ValueOf(fakedValue).Uint()), nil
59 | case reflect.Uint64:
60 | return uint64(reflect.ValueOf(fakedValue).Uint()), nil
61 | case reflect.Float32:
62 | return float32(reflect.ValueOf(fakedValue).Float()), nil
63 | case reflect.Float64:
64 | return float64(reflect.ValueOf(fakedValue).Float()), nil
65 | case reflect.Slice, reflect.Array:
66 | return reflect.ValueOf(fakedValue).Interface(), nil
67 | case reflect.Map:
68 | return reflect.ValueOf(fakedValue).Interface(), nil
69 | case reflect.Struct:
70 | return reflect.ValueOf(fakedValue).Interface(), nil
71 |
72 | default:
73 | return nil, fmt.Errorf("unsupported type %q", k)
74 | }
75 | }
76 |
77 | func containsKind(possibleKinds []reflect.Kind, kind reflect.Kind) bool {
78 | for _, k := range possibleKinds {
79 | if k == kind {
80 | return true
81 | }
82 | }
83 | return false
84 | }
85 |
--------------------------------------------------------------------------------
/fakeable_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "math"
6 | "reflect"
7 | "testing"
8 | )
9 |
10 | type strTyp string
11 |
12 | func (t strTyp) Fake(faker *Faker) (any, error) {
13 | return faker.FirstName(), nil
14 | }
15 |
16 | type strTypPtr string
17 |
18 | func (t *strTypPtr) Fake(faker *Faker) (any, error) {
19 | return strTypPtr("hello test ptr"), nil
20 | }
21 |
22 | type testStruct1 struct {
23 | B string `fake:"{firstname}"`
24 | }
25 |
26 | type testStruct2 struct {
27 | B strTyp
28 | }
29 |
30 | func TestIsFakeable(t *testing.T) {
31 | var t1 testStruct2
32 | var t2 *testStruct2
33 | var t3 strTyp
34 | var t4 *strTyp
35 | var t5 strTypPtr
36 | var t6 *strTypPtr
37 |
38 | if isFakeable(reflect.ValueOf(t1).Type()) {
39 | t.Errorf("expected testStruct2 not to be fakeable")
40 | }
41 |
42 | if isFakeable(reflect.ValueOf(t2).Type()) {
43 | t.Errorf("expected *testStruct2 not to be fakeable")
44 | }
45 |
46 | if !isFakeable(reflect.ValueOf(t3).Type()) {
47 | t.Errorf("expected strTyp to be fakeable")
48 | }
49 |
50 | if !isFakeable(reflect.ValueOf(t4).Type()) {
51 | t.Errorf("expected *strTyp to be fakeable")
52 | }
53 |
54 | if !isFakeable(reflect.ValueOf(t5).Type()) {
55 | t.Errorf("expected strTypPtr to be fakeable")
56 | }
57 |
58 | if !isFakeable(reflect.ValueOf(t6).Type()) {
59 | t.Errorf("expected *strTypPtr to be fakeable")
60 | }
61 | }
62 |
63 | func ExampleFakeable() {
64 | var t1 testStruct1
65 | var t2 testStruct1
66 | var t3 testStruct2
67 | var t4 testStruct2
68 | New(314).Struct(&t1)
69 | New(314).Struct(&t2)
70 | New(314).Struct(&t3)
71 | New(314).Struct(&t4)
72 |
73 | fmt.Printf("%#v\n", t1)
74 | fmt.Printf("%#v\n", t2)
75 | fmt.Printf("%#v\n", t3)
76 | fmt.Printf("%#v\n", t4)
77 |
78 | // Output: gofakeit.testStruct1{B:"Colton"}
79 | // gofakeit.testStruct1{B:"Colton"}
80 | // gofakeit.testStruct2{B:"Colton"}
81 | // gofakeit.testStruct2{B:"Colton"}
82 | }
83 |
84 | type gammaFloat64 float64
85 |
86 | func (gammaFloat64) Fake(f *Faker) (any, error) {
87 | alpha := 2.0
88 |
89 | // Generate a random value from the Gamma distribution
90 | var r float64
91 | for r == 0 {
92 | u := f.Float64Range(0, 1)
93 | v := f.Float64Range(0, 1)
94 | w := u * (1 - u)
95 | y := math.Sqrt(-2 * math.Log(w) / w)
96 | x := alpha * (y*v + u - 0.5)
97 | if x > 0 {
98 | r = x
99 | }
100 | }
101 | return gammaFloat64(r), nil
102 | }
103 |
104 | func ExampleFakeable_gammaFloat64() {
105 | f1 := New(100)
106 |
107 | // Fakes random values from the Gamma distribution
108 | var A1 gammaFloat64
109 | var A2 gammaFloat64
110 | var A3 gammaFloat64
111 | f1.Struct(&A1)
112 | f1.Struct(&A2)
113 | f1.Struct(&A3)
114 |
115 | fmt.Println(A1)
116 | fmt.Println(A2)
117 | fmt.Println(A3)
118 |
119 | // Output: 1.9058272589164647
120 | // 1.951453943304136
121 | // 4.336093466276675
122 | }
123 |
124 | type poissonInt64 int64
125 |
126 | func (poissonInt64) Fake(faker *Faker) (any, error) {
127 | lambda := 15.0
128 |
129 | // Generate a random value from the Poisson distribution
130 | var k int64
131 | var p float64 = 1.0
132 | var L float64 = math.Exp(-lambda)
133 | for p > L {
134 | u := faker.Float64Range(0, 1)
135 | p *= u
136 | k++
137 | }
138 | return poissonInt64(k - 1), nil
139 | }
140 |
141 | type employee struct {
142 | Name string `fake:"{firstname} {lastname}"`
143 | CallCountPerHour poissonInt64
144 | }
145 |
146 | func ExampleFakeable_employee() {
147 | f1 := New(100)
148 |
149 | // Fakes random values from the Gamma distribution
150 | var A1 employee
151 | var A2 employee
152 | var A3 employee
153 | f1.Struct(&A1)
154 | f1.Struct(&A2)
155 | f1.Struct(&A3)
156 |
157 | fmt.Printf("%#v\n", A1)
158 | fmt.Printf("%#v\n", A2)
159 | fmt.Printf("%#v\n", A3)
160 |
161 | // Output: gofakeit.employee{Name:"Madelynn Hickle", CallCountPerHour:17}
162 | // gofakeit.employee{Name:"Brooke Berge", CallCountPerHour:8}
163 | // gofakeit.employee{Name:"Rosalee Roberts", CallCountPerHour:10}
164 | }
165 |
--------------------------------------------------------------------------------
/faker.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "errors"
5 | "math/rand/v2"
6 | "reflect"
7 | "sync"
8 |
9 | "github.com/brianvoe/gofakeit/v7/source"
10 | )
11 |
12 | // Create global variable to deal with global function call
13 | var GlobalFaker *Faker = New(0)
14 |
15 | // Faker struct is the primary struct for using localized
16 | type Faker struct {
17 | Rand rand.Source
18 |
19 | // Lock to make thread safe
20 | Locked bool
21 | mu sync.Mutex
22 | }
23 |
24 | // New creates and returns a new Faker struct seeded with a given seed
25 | // using the PCG algorithm in lock mode for thread safety
26 | func New(seed uint64) *Faker {
27 | // If seed is 0, use a random crypto seed
28 | if seed == 0 {
29 | faker := NewFaker(source.NewCrypto(), false)
30 | seed = faker.Uint64()
31 | }
32 |
33 | return &Faker{
34 | Rand: rand.NewPCG(seed, seed),
35 | Locked: true,
36 | }
37 | }
38 |
39 | // NewFaker takes in a rand.Source and thread lock state and returns a new Faker struct
40 | func NewFaker(src rand.Source, lock bool) *Faker {
41 | return &Faker{
42 | Rand: src,
43 | Locked: lock,
44 | }
45 | }
46 |
47 | // Seed attempts to seed the Faker with the given seed
48 | func (f *Faker) Seed(args ...any) error {
49 | // Lock if locked
50 | if f.Locked {
51 | f.mu.Lock()
52 | defer f.mu.Unlock()
53 | }
54 |
55 | // Ensure GlobalFaker is not nil and Rand is initialized
56 | if GlobalFaker == nil || GlobalFaker.Rand == nil {
57 | return errors.New("GlobalFaker or GlobalFaker.Rand is nil")
58 | }
59 |
60 | // If args is empty or 0, seed with a random crypto seed
61 | if len(args) == 0 {
62 | faker := NewFaker(source.NewCrypto(), false)
63 | args = append(args, faker.Uint64())
64 | }
65 |
66 | if args[0] == 0 {
67 | faker := NewFaker(source.NewCrypto(), false)
68 | args[0] = faker.Uint64()
69 | }
70 |
71 | // Retrieve the Seed method
72 | method := reflect.ValueOf(GlobalFaker.Rand).MethodByName("Seed")
73 | if !method.IsValid() {
74 | return errors.New("Seed method not found")
75 | }
76 |
77 | // Adjust args if method requires exactly 2 args but only 1 was provided
78 | if method.Type().NumIn() == 2 && len(args) == 1 {
79 | args = append(args, args[0]) // Duplicate the first value if only one is provided
80 | }
81 |
82 | // Get array of function argument types and prepare converted arguments
83 | argTypes := make([]reflect.Type, method.Type().NumIn())
84 | convertedArgs := make([]reflect.Value, len(args))
85 | for i := 0; i < method.Type().NumIn(); i++ {
86 | argTypes[i] = method.Type().In(i)
87 | }
88 |
89 | // Convert args to the expected type by the Seed method
90 | for i, arg := range args {
91 | if i < len(argTypes) { // Ensure arg index is within argTypes bounds
92 | argValue := reflect.ValueOf(arg)
93 | // Check if conversion is necessary
94 | if argValue.Type().ConvertibleTo(argTypes[i]) {
95 | convertedArgs[i] = argValue.Convert(argTypes[i])
96 | } else {
97 | // If not convertible, use the argument as is (reflectively)
98 | convertedArgs[i] = argValue
99 | }
100 | }
101 | }
102 |
103 | // Dynamically call the Seed method with converted arguments
104 | method.Call(convertedArgs)
105 |
106 | return nil
107 | }
108 |
109 | // Seed attempts to seed the GlobalFaker with the given seed
110 | func Seed(args ...any) error {
111 | return GlobalFaker.Seed(args...)
112 | }
113 |
--------------------------------------------------------------------------------
/faker_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "math/rand/v2"
6 | "sync"
7 | "testing"
8 | )
9 |
10 | func Example() {
11 | Seed(11)
12 |
13 | fmt.Println("Name:", Name())
14 | fmt.Println("Email:", Email())
15 | fmt.Println("Phone:", Phone())
16 | fmt.Println("Address:", Address().Address)
17 | fmt.Println("BS:", BS())
18 | fmt.Println("Beer Name:", BeerName())
19 | fmt.Println("Color:", Color())
20 | fmt.Println("Company:", Company())
21 | fmt.Println("Credit Card:", CreditCardNumber(nil))
22 | fmt.Println("Hacker Phrase:", HackerPhrase())
23 | fmt.Println("Job Title:", JobTitle())
24 | fmt.Println("Password:", Password(true, true, true, true, false, 32))
25 |
26 | // Output: Name: Sonny Stiedemann
27 | // Email: codydonnelly@leannon.biz
28 | // Phone: 7598907999
29 | // Address: 4737 Port Hillstown, Santa Ana, Alabama 41026
30 | // BS: enable
31 | // Beer Name: Chocolate St
32 | // Color: Turquoise
33 | // Company: Boundless
34 | // Credit Card: 6282690620525711
35 | // Hacker Phrase: Try to bundle the PNG firewall, maybe it will deconstruct the open-source bandwidth!
36 | // Job Title: Assistant
37 | // Password: Nyf8p8ka1Kvgn...3H*.w7j01yM1vkc2
38 | }
39 |
40 | func ExampleNew() {
41 | // Get new faker with default settings
42 | fake := New(11)
43 |
44 | // All global functions are also available in the structs methods
45 | fmt.Println("Name:", fake.Name())
46 | fmt.Println("Email:", fake.Email())
47 | fmt.Println("Phone:", fake.Phone())
48 |
49 | // Output:
50 | // Name: Sonny Stiedemann
51 | // Email: codydonnelly@leannon.biz
52 | // Phone: 7598907999
53 | }
54 |
55 | func ExampleNewFaker() {
56 | // Create new faker with ChaCha8, cryptographically secure
57 | chacha := rand.NewChaCha8([32]byte{5, 4, 3, 2, 1, 0})
58 | fake := NewFaker(chacha, true)
59 |
60 | // or
61 |
62 | // Create new faker with PCG, pseudo-random
63 | pcg := rand.NewPCG(0, 0)
64 | fake = NewFaker(pcg, false)
65 |
66 | fmt.Println("Name:", fake.Name())
67 |
68 | // Output:
69 | // Name: Damian Pagac
70 | }
71 |
72 | func TestSeed(t *testing.T) {
73 | // Test crypto that has no parameters in Seed
74 | GlobalFaker = New(11)
75 |
76 | // Test a simple function
77 | name := Name()
78 |
79 | // Seed
80 | err := Seed(11)
81 | if err != nil {
82 | t.Error(err)
83 | }
84 |
85 | // Make sure name is the same
86 | if name != Name() {
87 | t.Error("Name was different after seed")
88 | }
89 | }
90 |
91 | func TestSetGlobalFaker(t *testing.T) {
92 | // Set global to crypto
93 | crypto := rand.NewPCG(11, 11)
94 | GlobalFaker = NewFaker(crypto, true)
95 |
96 | // Test a simple function
97 | name := Name()
98 | if name == "" {
99 | t.Error("Name was empty")
100 | }
101 |
102 | // Set global back to default
103 | GlobalFaker = New(0)
104 | }
105 |
106 | func TestConcurrency(t *testing.T) {
107 | var setupComplete sync.WaitGroup
108 | setupComplete.Add(1)
109 |
110 | var wg sync.WaitGroup
111 | for i := 0; i < 1000; i++ {
112 | wg.Add(1)
113 | go func() {
114 | setupComplete.Wait()
115 | Paragraph(1, 5, 20, " ")
116 | wg.Done()
117 | }()
118 | }
119 |
120 | setupComplete.Done()
121 | wg.Wait()
122 | }
123 |
--------------------------------------------------------------------------------
/file.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | // FileExtension will generate a random file extension
4 | func FileExtension() string { return fileExtension(GlobalFaker) }
5 |
6 | // FileExtension will generate a random file extension
7 | func (f *Faker) FileExtension() string { return fileExtension(f) }
8 |
9 | func fileExtension(f *Faker) string { return getRandValue(f, []string{"file", "extension"}) }
10 |
11 | // FileMimeType will generate a random mime file type
12 | func FileMimeType() string { return fileMimeType(GlobalFaker) }
13 |
14 | // FileMimeType will generate a random mime file type
15 | func (f *Faker) FileMimeType() string { return fileMimeType(f) }
16 |
17 | func fileMimeType(f *Faker) string { return getRandValue(f, []string{"file", "mime_type"}) }
18 |
19 | func addFileLookup() {
20 | AddFuncLookup("fileextension", Info{
21 | Display: "File Extension",
22 | Category: "file",
23 | Description: "Suffix appended to a filename indicating its format or type",
24 | Example: "nes",
25 | Output: "string",
26 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
27 | return fileExtension(f), nil
28 | },
29 | })
30 |
31 | AddFuncLookup("filemimetype", Info{
32 | Display: "File Mime Type",
33 | Category: "file",
34 | Description: "Defines file format and nature for browsers and email clients using standardized identifiers",
35 | Example: "application/json",
36 | Output: "string",
37 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
38 | return fileMimeType(f), nil
39 | },
40 | })
41 | }
42 |
--------------------------------------------------------------------------------
/file_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleFileMimeType() {
9 | Seed(11)
10 | fmt.Println(FileMimeType())
11 |
12 | // Output: application/x-wri
13 | }
14 |
15 | func ExampleFaker_FileMimeType() {
16 | f := New(11)
17 | fmt.Println(f.FileMimeType())
18 |
19 | // Output: application/x-wri
20 | }
21 |
22 | func BenchmarkFileMimeType(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | FileMimeType()
25 | }
26 | }
27 |
28 | func ExampleFileExtension() {
29 | Seed(11)
30 | fmt.Println(FileExtension())
31 |
32 | // Output: dtd
33 | }
34 |
35 | func ExampleFaker_FileExtension() {
36 | f := New(11)
37 | fmt.Println(f.FileExtension())
38 |
39 | // Output: dtd
40 | }
41 |
42 | func BenchmarkFileExtension(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | FileExtension()
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/finance.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "strconv"
5 | "unicode"
6 | )
7 |
8 | const cusipStr = upperStr + numericStr
9 |
10 | // CUSIP
11 | func Cusip() string {
12 | return cusip(GlobalFaker)
13 | }
14 |
15 | func (f *Faker) Cusip() string {
16 | return cusip(f)
17 | }
18 |
19 | func cusip(f *Faker) string {
20 | cusipBytes := make([]byte, 8)
21 | for i := 0; i < len(cusipBytes); i++ {
22 | cusipBytes[i] = byte(cusipStr[f.IntN(len(cusipStr))])
23 | }
24 |
25 | baseCusip := string(cusipBytes)
26 |
27 | chkDigit := cusipChecksumDigit(baseCusip)
28 | return baseCusip + chkDigit
29 | }
30 |
31 | // ISIN
32 | func Isin() string {
33 | return isin(GlobalFaker)
34 | }
35 |
36 | func (f *Faker) Isin() string {
37 | return isin(f)
38 | }
39 |
40 | func isin(f *Faker) string {
41 | countryCode := countryAbr(f)
42 | nsin := cusip(f)
43 | isinChkDig := isinChecksumDigit(countryCode + nsin)
44 | return countryCode + nsin + isinChkDig
45 | }
46 |
47 | // cusipChecksumDigit returns the checksum digit for a CUSIP
48 | func cusipChecksumDigit(cusip string) string {
49 | sum := 0
50 | for i, c := range cusip {
51 | v := 0
52 | if unicode.IsDigit(c) {
53 | v = int(c - '0')
54 | }
55 | if unicode.IsLetter(c) {
56 | //0-indexed ordinal position of Letter + 10
57 | v = int(c-'A') + 10
58 | }
59 | if i%2 != 0 {
60 | // Multiply odd digits by two
61 | v = v * 2
62 | }
63 |
64 | sum = sum + int(v/10) + v%10
65 | }
66 |
67 | return strconv.Itoa((10 - (sum % 10)) % 10)
68 | }
69 |
70 | // isinChecksumDigit returns the checksum digit for an ISIN
71 | func isinChecksumDigit(isin string) string {
72 | isinDigits := make([]int, 0)
73 | for _, c := range isin {
74 | if unicode.IsLetter(c) {
75 | letterVal := int(c) - 55
76 | // Each digit is added as a separate value
77 | isinDigits = append(isinDigits, letterVal/10)
78 | isinDigits = append(isinDigits, letterVal%10)
79 | }
80 | if unicode.IsDigit(c) {
81 | isinDigits = append(isinDigits, int(c-'0'))
82 | }
83 | }
84 |
85 | oddSum := 0
86 | evenSum := 0
87 |
88 | // Take the per digit sum of the digitized ISIN, doubling even indexed digits
89 | for i, d := range isinDigits {
90 | if i%2 == 0 {
91 | elem := 2 * d
92 | if elem > 9 {
93 | // If the element now has two digits, sum those digits
94 | elem = (elem % 10) + (elem / 10)
95 | }
96 | evenSum += elem
97 | } else {
98 | oddSum += d
99 | }
100 | }
101 |
102 | return strconv.Itoa((10 - (oddSum+evenSum)%10) % 10)
103 | }
104 |
105 | // Lookup Adds
106 | func addFinanceLookup() {
107 | AddFuncLookup("cusip", Info{
108 | Display: "CUSIP",
109 | Category: "finance",
110 | Description: "Unique identifier for securities, especially bonds, in the United States and Canada",
111 | Example: "38259P508",
112 | Output: "string",
113 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
114 | return cusip(f), nil
115 | },
116 | })
117 | AddFuncLookup("isin", Info{
118 | Display: "ISIN",
119 | Category: "finance",
120 | Description: "International standard code for uniquely identifying securities worldwide",
121 | Example: "CVLRQCZBXQ97",
122 | Output: "string",
123 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
124 | return isin(f), nil
125 | },
126 | })
127 | }
128 |
--------------------------------------------------------------------------------
/finance_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | // CUSIP Tests
9 | func ExampleCusip() {
10 | Seed(11)
11 | fmt.Println(Cusip())
12 |
13 | // Output: 64HHTI0T8
14 | }
15 |
16 | func ExampleFaker_Cusip() {
17 | f := New(11)
18 | fmt.Println(f.Cusip())
19 |
20 | // Output: 64HHTI0T8
21 | }
22 |
23 | func TestCusip(t *testing.T) {
24 | Seed(11)
25 | cusip := Cusip()
26 | if cusip == "" {
27 | t.Error("Valid Cusips are not blank")
28 | }
29 | if len(cusip) != 9 {
30 | t.Error("Valid Cusips are 9 characters in length")
31 | }
32 | if cusipChecksumDigit(cusip[:8]) != string(cusip[8]) {
33 | t.Error("Generated Cusip has invalid checksum")
34 | }
35 | }
36 |
37 | func TestCusipCheckDigit(t *testing.T) {
38 | type test struct {
39 | base string
40 | want string
41 | }
42 |
43 | tests := []test{
44 | {base: "03783310", want: "0"},
45 | {base: "17275R10", want: "2"},
46 | {base: "38259P50", want: "8"},
47 | }
48 | for _, tc := range tests {
49 | digit := cusipChecksumDigit(tc.base)
50 | if digit != tc.want {
51 | t.Errorf("Expected check digit of %s, got %s", tc.want, digit)
52 | }
53 | }
54 | }
55 |
56 | func BenchmarkCusip(b *testing.B) {
57 | for i := 0; i < b.N; i++ {
58 | Cusip()
59 | }
60 | }
61 |
62 | // ISIN Tests
63 | func ExampleIsin() {
64 | Seed(11)
65 | fmt.Println(Isin())
66 |
67 | // Output: TO4HHTI0T819
68 | }
69 |
70 | func ExampleFaker_Isin() {
71 | f := New(11)
72 | fmt.Println(f.Isin())
73 |
74 | // Output: TO4HHTI0T819
75 | }
76 |
77 | func TestIsin(t *testing.T) {
78 | Seed(11)
79 | isin := Isin()
80 | if isin == "" {
81 | t.Error("Valid ISINs are not blank")
82 | }
83 | if len(isin) != 12 {
84 | t.Error("Valid ISINs are 12 characters in length")
85 | }
86 | if isinChecksumDigit(isin[:11]) != string(isin[11]) {
87 | t.Error("Generated ISIN has invalid check digit")
88 | }
89 | }
90 |
91 | func TestIsinCheckDigit(t *testing.T) {
92 | type test struct {
93 | base string
94 | want string
95 | }
96 |
97 | tests := []test{
98 | {base: "US037833100", want: "5"},
99 | {base: "GB000263494", want: "6"},
100 | {base: "US000402625", want: "0"},
101 | }
102 | for _, tc := range tests {
103 | digit := isinChecksumDigit(tc.base)
104 | if digit != tc.want {
105 | t.Errorf("Expected check digit of %s, got %s", tc.want, digit)
106 | }
107 | }
108 | }
109 |
110 | func BenchmarkIsin(b *testing.B) {
111 | for i := 0; i < b.N; i++ {
112 | Isin()
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/food_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleFruit() {
9 | Seed(11)
10 | fmt.Println(Fruit())
11 |
12 | // Output: Redcurrant
13 | }
14 |
15 | func ExampleFaker_Fruit() {
16 | f := New(11)
17 | fmt.Println(f.Fruit())
18 |
19 | // Output: Redcurrant
20 | }
21 |
22 | func BenchmarkFruit(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Fruit()
25 | }
26 | }
27 |
28 | func ExampleVegetable() {
29 | Seed(11)
30 | fmt.Println(Vegetable())
31 |
32 | // Output: Sweet Potato
33 | }
34 |
35 | func ExampleFaker_Vegetable() {
36 | f := New(11)
37 | fmt.Println(f.Vegetable())
38 |
39 | // Output: Sweet Potato
40 | }
41 |
42 | func BenchmarkVegetable(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | Vegetable()
45 | }
46 | }
47 |
48 | func ExampleBreakfast() {
49 | Seed(11)
50 | fmt.Println(Breakfast())
51 |
52 | // Output: Purple cow
53 | }
54 |
55 | func ExampleFaker_Breakfast() {
56 | f := New(11)
57 | fmt.Println(f.Breakfast())
58 |
59 | // Output: Purple cow
60 | }
61 |
62 | func BenchmarkBreakfast(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | Breakfast()
65 | }
66 | }
67 |
68 | func ExampleLunch() {
69 | Seed(11)
70 | fmt.Println(Lunch())
71 |
72 | // Output: Quick chile relleno casserole
73 | }
74 |
75 | func ExampleFaker_Lunch() {
76 | f := New(11)
77 | fmt.Println(f.Lunch())
78 |
79 | // Output: Quick chile relleno casserole
80 | }
81 |
82 | func BenchmarkLunch(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | Lunch()
85 | }
86 | }
87 |
88 | func ExampleDinner() {
89 | Seed(11)
90 | fmt.Println(Dinner())
91 |
92 | // Output: German apple cake with cream cheese frosting
93 | }
94 |
95 | func ExampleFaker_Dinner() {
96 | f := New(11)
97 | fmt.Println(f.Dinner())
98 |
99 | // Output: German apple cake with cream cheese frosting
100 | }
101 |
102 | func BenchmarkDinner(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | Dinner()
105 | }
106 | }
107 |
108 | func ExampleDrink() {
109 | Seed(11)
110 | fmt.Println(Drink())
111 |
112 | // Output: Wine
113 | }
114 |
115 | func ExampleFaker_Drink() {
116 | f := New(11)
117 | fmt.Println(f.Drink())
118 |
119 | // Output: Wine
120 | }
121 |
122 | func BenchmarkDrink(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | Drink()
125 | }
126 | }
127 |
128 | func ExampleSnack() {
129 | Seed(11)
130 | fmt.Println(Snack())
131 |
132 | // Output: Fantastic banana bran muffins
133 | }
134 |
135 | func ExampleFaker_Snack() {
136 | f := New(11)
137 | fmt.Println(f.Snack())
138 |
139 | // Output: Fantastic banana bran muffins
140 | }
141 |
142 | func BenchmarkSnack(b *testing.B) {
143 | for i := 0; i < b.N; i++ {
144 | Snack()
145 | }
146 | }
147 |
148 | func ExampleDessert() {
149 | Seed(11)
150 | fmt.Println(Dessert())
151 |
152 | // Output: Amish cream pie
153 | }
154 |
155 | func ExampleFaker_Dessert() {
156 | f := New(11)
157 | fmt.Println(f.Dessert())
158 |
159 | // Output: Amish cream pie
160 | }
161 |
162 | func BenchmarkDessert(b *testing.B) {
163 | for i := 0; i < b.N; i++ {
164 | Dessert()
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/game.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 | )
7 |
8 | // Gamertag will generate a random video game username
9 | func Gamertag() string { return gamertag(GlobalFaker) }
10 |
11 | // Gamertag will generate a random video game username
12 | func (f *Faker) Gamertag() string { return gamertag(f) }
13 |
14 | func gamertag(f *Faker) string {
15 | str := ""
16 | num := number(f, 1, 4)
17 | switch num {
18 | case 1:
19 | str = fmt.Sprintf("%s%ser", title(nounConcrete(f)), title(verbAction(f)))
20 | case 2:
21 | str = fmt.Sprintf("%s%s", title(adjectiveDescriptive(f)), title(animal(f)))
22 | case 3:
23 | str = fmt.Sprintf("%s%s", title(adjectiveDescriptive(f)), title(nounConcrete(f)))
24 | case 4:
25 | str = fmt.Sprintf("%s%s", title(fruit(f)), title(adjectiveDescriptive(f)))
26 | }
27 |
28 | // Randomly determine if we should add a number
29 | if f.IntN(3) == 1 {
30 | str += digitN(f, uint(number(f, 1, 3)))
31 | }
32 |
33 | // Remove any spaces
34 | str = strings.Replace(str, " ", "", -1)
35 |
36 | return str
37 | }
38 |
39 | // Dice will generate a random set of dice
40 | func Dice(numDice uint, sides []uint) []uint { return dice(GlobalFaker, numDice, sides) }
41 |
42 | // Dice will generate a random set of dice
43 | func (f *Faker) Dice(numDice uint, sides []uint) []uint { return dice(f, numDice, sides) }
44 |
45 | func dice(f *Faker, numDice uint, sides []uint) []uint {
46 | dice := make([]uint, numDice)
47 |
48 | // If we dont have any sides well set the sides to 6
49 | if len(sides) == 0 {
50 | sides = []uint{6}
51 | }
52 |
53 | for i := range dice {
54 | // If sides[i] doesnt exist use the first side
55 | if len(sides)-1 < i {
56 | dice[i] = uint(number(f, 1, int(sides[0])))
57 | } else {
58 | dice[i] = uint(number(f, 1, int(sides[i])))
59 | }
60 | }
61 |
62 | return dice
63 | }
64 |
65 | func addGameLookup() {
66 | AddFuncLookup("gamertag", Info{
67 | Display: "Gamertag",
68 | Category: "game",
69 | Description: "User-selected online username or alias used for identification in games",
70 | Example: "footinterpret63",
71 | Output: "string",
72 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
73 | return gamertag(f), nil
74 | },
75 | })
76 |
77 | AddFuncLookup("dice", Info{
78 | Display: "Dice",
79 | Category: "game",
80 | Description: "Small, cube-shaped objects used in games of chance for random outcomes",
81 | Example: "[5, 2, 3]",
82 | Output: "[]uint",
83 | Params: []Param{
84 | {Field: "numdice", Display: "Number of Dice", Type: "uint", Default: "1", Description: "Number of dice to roll"},
85 | {Field: "sides", Display: "Number of Sides", Type: "[]uint", Default: "[6]", Description: "Number of sides on each dice"},
86 | },
87 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
88 | numDice, err := info.GetUint(m, "numdice")
89 | if err != nil {
90 | return nil, err
91 | }
92 |
93 | sides, err := info.GetUintArray(m, "sides")
94 | if err != nil {
95 | return nil, err
96 | }
97 |
98 | return dice(f, numDice, sides), nil
99 | },
100 | })
101 | }
102 |
--------------------------------------------------------------------------------
/game_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleGamertag() {
9 | Seed(11)
10 | fmt.Println(Gamertag())
11 |
12 | // Output: TurkeyThinker
13 | }
14 |
15 | func ExampleFaker_Gamertag() {
16 | f := New(11)
17 | fmt.Println(f.Gamertag())
18 |
19 | // Output: TurkeyThinker
20 | }
21 |
22 | func TestGamertag(t *testing.T) {
23 | for i := 0; i < 100; i++ {
24 | g := Gamertag()
25 | if g == "" {
26 | t.Errorf("Gamertag() returned empty string")
27 | }
28 | }
29 | }
30 |
31 | func BenchmarkGamertag(b *testing.B) {
32 | for i := 0; i < b.N; i++ {
33 | Gamertag()
34 | }
35 | }
36 |
37 | func ExampleDice() {
38 | Seed(11)
39 | fmt.Println(Dice(1, []uint{6}))
40 |
41 | // Output: [6]
42 | }
43 |
44 | func ExampleFaker_Dice() {
45 | f := New(11)
46 | fmt.Println(f.Dice(1, []uint{6}))
47 |
48 | // Output: [6]
49 | }
50 |
51 | func TestDice(t *testing.T) {
52 | for i := 0; i < 100; i++ {
53 | // put together random number of dice and sides
54 | numDice := uint(Number(1, 10))
55 | sides := make([]uint, numDice)
56 | for i := 0; i < int(numDice); i++ {
57 | sides[i] = uint(Number(1, 10))
58 | }
59 |
60 | g := Dice(numDice, sides)
61 | if len(g) == 0 {
62 | t.Errorf("Dice() returned empty uint array")
63 | }
64 |
65 | // Make sure the length of the array is the same as the number of dice
66 | if len(g) != int(numDice) {
67 | t.Errorf("Dice() returned wrong length array")
68 | }
69 | }
70 | }
71 |
72 | func TestDiceNoSides(t *testing.T) {
73 | for i := 0; i < 100; i++ {
74 | g := Dice(1, []uint{})
75 | if len(g) != 1 {
76 | t.Errorf("Dice() returned non-empty array")
77 | }
78 |
79 | // Make sure g[1] is betwwen 1 and 6
80 | if g[0] < 1 || g[0] > 6 {
81 | t.Errorf("Dice() returned wrong number")
82 | }
83 | }
84 | }
85 |
86 | func TestDiceOneSide(t *testing.T) {
87 | for i := 0; i < 100; i++ {
88 | g := Dice(10, []uint{1})
89 | if len(g) != 10 {
90 | t.Errorf("Dice() returned non 10 value array")
91 | }
92 |
93 | // Make sure all g values are 1
94 | for _, v := range g {
95 | if v != 1 {
96 | t.Errorf("Dice() returned wrong number")
97 | }
98 | }
99 | }
100 | }
101 |
102 | func BenchmarkDice(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | Dice(1, []uint{6})
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/brianvoe/gofakeit/v7
2 |
3 | go 1.22
4 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brianvoe/gofakeit/b3820daba293d107191129e516fb396e03a70a31/go.sum
--------------------------------------------------------------------------------
/hacker_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleHackerPhrase() {
9 | Seed(11)
10 | fmt.Println(HackerPhrase())
11 |
12 | // Output: Use the optical CSS microchip, then you can write the open-source monitor!
13 | }
14 |
15 | func ExampleFaker_HackerPhrase() {
16 | f := New(11)
17 | fmt.Println(f.HackerPhrase())
18 |
19 | // Output: Use the optical CSS microchip, then you can write the open-source monitor!
20 | }
21 |
22 | func BenchmarkHackerPhrase(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | HackerPhrase()
25 | }
26 | }
27 |
28 | func ExampleHackerAbbreviation() {
29 | Seed(11)
30 | fmt.Println(HackerAbbreviation())
31 |
32 | // Output: SCSI
33 | }
34 |
35 | func ExampleFaker_HackerAbbreviation() {
36 | f := New(11)
37 | fmt.Println(f.HackerAbbreviation())
38 |
39 | // Output: SCSI
40 | }
41 |
42 | func BenchmarkHackerAbbreviation(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | HackerAbbreviation()
45 | }
46 | }
47 |
48 | func ExampleHackerAdjective() {
49 | Seed(11)
50 | fmt.Println(HackerAdjective())
51 |
52 | // Output: solid state
53 | }
54 |
55 | func ExampleFaker_HackerAdjective() {
56 | f := New(11)
57 | fmt.Println(f.HackerAdjective())
58 |
59 | // Output: solid state
60 | }
61 |
62 | func BenchmarkHackerAdjective(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | HackerAdjective()
65 | }
66 | }
67 |
68 | func ExampleHackerNoun() {
69 | Seed(11)
70 | fmt.Println(HackerNoun())
71 |
72 | // Output: circuit
73 | }
74 |
75 | func ExampleFaker_HackerNoun() {
76 | f := New(11)
77 | fmt.Println(f.HackerNoun())
78 |
79 | // Output: circuit
80 | }
81 |
82 | func BenchmarkHackerNoun(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | HackerNoun()
85 | }
86 | }
87 |
88 | func ExampleHackerVerb() {
89 | Seed(11)
90 | fmt.Println(HackerVerb())
91 |
92 | // Output: lock
93 | }
94 |
95 | func ExampleFaker_HackerVerb() {
96 | f := New(11)
97 | fmt.Println(f.HackerVerb())
98 |
99 | // Output: lock
100 | }
101 |
102 | func BenchmarkHackerVerb(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | HackerVerb()
105 | }
106 | }
107 |
108 | func ExampleHackeringVerb() {
109 | Seed(11)
110 | fmt.Println(HackeringVerb())
111 |
112 | // Output: compressing
113 | }
114 |
115 | func ExampleFaker_HackeringVerb() {
116 | f := New(11)
117 | fmt.Println(f.HackeringVerb())
118 |
119 | // Output: compressing
120 | }
121 |
122 | func BenchmarkHackeringVerb(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | HackeringVerb()
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/hipster_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleHipsterWord() {
9 | Seed(11)
10 | fmt.Println(HipsterWord())
11 |
12 | // Output: semiotics
13 | }
14 |
15 | func ExampleFaker_HipsterWord() {
16 | f := New(11)
17 | fmt.Println(f.HipsterWord())
18 |
19 | // Output: semiotics
20 | }
21 |
22 | func BenchmarkHipsterWord(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | HipsterWord()
25 | }
26 | }
27 |
28 | func ExampleHipsterSentence() {
29 | Seed(11)
30 | fmt.Println(HipsterSentence(5))
31 |
32 | // Output: Semiotics everyday you probably haven't heard of them you probably haven't heard of them portland.
33 | }
34 |
35 | func ExampleFaker_HipsterSentence() {
36 | f := New(11)
37 | fmt.Println(f.HipsterSentence(5))
38 |
39 | // Output: Semiotics everyday you probably haven't heard of them you probably haven't heard of them portland.
40 | }
41 |
42 | func BenchmarkHipsterSentence(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | HipsterSentence(10)
45 | }
46 | }
47 |
48 | func ExampleHipsterParagraph() {
49 | Seed(11)
50 | fmt.Println(HipsterParagraph(3, 5, 12, "\n"))
51 |
52 | // Output: Semiotics everyday you probably haven't heard of them you probably haven't heard of them portland austin tattooed retro cardigan Yuccie cred hoodie. Vice pug pug cred intelligentsia roof helvetica squid chambray literally ennui ugh. Chicharrones messenger bag narwhal ennui flannel twee art party mustache sartorial gluten-free cardigan cronut. Hoodie kickstarter cardigan Thundercats heirloom hashtag bitters salvia cleanse forage chartreuse keffiyeh. Sustainable tofu mustache bespoke vice aesthetic iPhone ugh lo-fi health put a bird on it blue bottle.
53 | // Pop-up pabst pitchfork literally roof tattooed tilde shoreditch green juice ethical celiac tilde. Kombucha kinfolk occupy tacos ramps 90's echo meditation kale chips gluten-free humblebrag keffiyeh. Lo-fi bespoke wayfarers chicharrones crucifix green juice humblebrag organic viral shabby chic locavore cred. Roof forage farm-to-table YOLO williamsburg crucifix blog everyday green juice listicle wayfarers post-ironic. Single-origin coffee cray organic YOLO disrupt venmo tofu meggings fanny pack master craft beer tofu.
54 | // Hella helvetica microdosing literally meh etsy echo pabst goth readymade +1 marfa. Pork belly hammock kale chips yr green juice stumptown crucifix hella pork belly franzen wolf austin. Offal cred chartreuse freegan intelligentsia twee trust fund paleo pinterest austin typewriter kogi. Pug single-origin coffee ethical irony helvetica beard green juice viral post-ironic Godard slow-carb put a bird on it. Schlitz hammock beard chia kitsch cred salvia irony farm-to-table loko truffaut ramps.
55 | }
56 |
57 | func ExampleFaker_HipsterParagraph() {
58 | f := New(11)
59 | fmt.Println(f.HipsterParagraph(3, 5, 12, "\n"))
60 |
61 | // Output: Semiotics everyday you probably haven't heard of them you probably haven't heard of them portland austin tattooed retro cardigan Yuccie cred hoodie. Vice pug pug cred intelligentsia roof helvetica squid chambray literally ennui ugh. Chicharrones messenger bag narwhal ennui flannel twee art party mustache sartorial gluten-free cardigan cronut. Hoodie kickstarter cardigan Thundercats heirloom hashtag bitters salvia cleanse forage chartreuse keffiyeh. Sustainable tofu mustache bespoke vice aesthetic iPhone ugh lo-fi health put a bird on it blue bottle.
62 | // Pop-up pabst pitchfork literally roof tattooed tilde shoreditch green juice ethical celiac tilde. Kombucha kinfolk occupy tacos ramps 90's echo meditation kale chips gluten-free humblebrag keffiyeh. Lo-fi bespoke wayfarers chicharrones crucifix green juice humblebrag organic viral shabby chic locavore cred. Roof forage farm-to-table YOLO williamsburg crucifix blog everyday green juice listicle wayfarers post-ironic. Single-origin coffee cray organic YOLO disrupt venmo tofu meggings fanny pack master craft beer tofu.
63 | // Hella helvetica microdosing literally meh etsy echo pabst goth readymade +1 marfa. Pork belly hammock kale chips yr green juice stumptown crucifix hella pork belly franzen wolf austin. Offal cred chartreuse freegan intelligentsia twee trust fund paleo pinterest austin typewriter kogi. Pug single-origin coffee ethical irony helvetica beard green juice viral post-ironic Godard slow-carb put a bird on it. Schlitz hammock beard chia kitsch cred salvia irony farm-to-table loko truffaut ramps.
64 | }
65 |
66 | func BenchmarkHipsterParagraph(b *testing.B) {
67 | for i := 0; i < b.N; i++ {
68 | HipsterParagraph(3, 5, 12, "\n")
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/html_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "strings"
6 | "testing"
7 |
8 | "github.com/brianvoe/gofakeit/v7/data"
9 | )
10 |
11 | func ExampleInputName() {
12 | Seed(11)
13 | fmt.Println(InputName())
14 |
15 | // Output: message
16 | }
17 |
18 | func ExampleFaker_InputName() {
19 | f := New(11)
20 | fmt.Println(f.InputName())
21 |
22 | // Output: message
23 | }
24 |
25 | func BenchmarkInputName(b *testing.B) {
26 | for i := 0; i < b.N; i++ {
27 | InputName()
28 | }
29 | }
30 |
31 | func TestSvg(t *testing.T) {
32 | Seed(11)
33 |
34 | // Loop through SvgTypes and set that type for each test
35 | var SvgTypes = data.GetSubData("html", "svg")
36 | for _, svgType := range SvgTypes {
37 | // Run the test
38 | t.Run(svgType, func(t *testing.T) {
39 |
40 | // Get the image
41 | img := Svg(&SVGOptions{
42 | Type: svgType,
43 | })
44 |
45 | // Check the image
46 | if img == "" {
47 | t.Error("Svg returned an empty string")
48 | }
49 |
50 | // Check the image
51 | if !strings.Contains(img, svgType) {
52 | t.Errorf("Svg returned an image of type %s, but should have been %s", svgType, svgType)
53 | }
54 | })
55 | }
56 | }
57 |
58 | func ExampleSvg() {
59 | Seed(11)
60 | fmt.Println(Svg(nil))
61 |
62 | // Output:
63 | }
64 |
65 | func ExampleFaker_Svg() {
66 | f := New(11)
67 | fmt.Println(f.Svg(nil))
68 |
69 | // Output:
70 | }
71 |
72 | func BenchmarkSvg(b *testing.B) {
73 | for i := 0; i < b.N; i++ {
74 | Svg(nil)
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/image.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "bytes"
5 | "errors"
6 | img "image"
7 | imgCol "image/color"
8 | "image/jpeg"
9 | "image/png"
10 | )
11 |
12 | // Image generates a random rgba image
13 | func Image(width int, height int) *img.RGBA { return image(GlobalFaker, width, height) }
14 |
15 | // Image generates a random rgba image
16 | func (f *Faker) Image(width int, height int) *img.RGBA { return image(f, width, height) }
17 |
18 | func image(f *Faker, width int, height int) *img.RGBA {
19 | upLeft := img.Point{0, 0}
20 | lowRight := img.Point{width, height}
21 |
22 | img := img.NewRGBA(img.Rectangle{upLeft, lowRight})
23 |
24 | // Set color for each pixel
25 | for x := 0; x < width; x++ {
26 | for y := 0; y < height; y++ {
27 | img.Set(x, y, imgCol.RGBA{uint8(number(f, 0, 255)), uint8(number(f, 0, 255)), uint8(number(f, 0, 255)), 0xff})
28 | }
29 | }
30 |
31 | return img
32 | }
33 |
34 | // ImageJpeg generates a random rgba jpeg image
35 | func ImageJpeg(width int, height int) []byte { return imageJpeg(GlobalFaker, width, height) }
36 |
37 | // ImageJpeg generates a random rgba jpeg image
38 | func (f *Faker) ImageJpeg(width int, height int) []byte { return imageJpeg(f, width, height) }
39 |
40 | func imageJpeg(f *Faker, width int, height int) []byte {
41 | buf := new(bytes.Buffer)
42 | jpeg.Encode(buf, image(f, width, height), nil)
43 | return buf.Bytes()
44 | }
45 |
46 | // ImagePng generates a random rgba png image
47 | func ImagePng(width int, height int) []byte { return imagePng(GlobalFaker, width, height) }
48 |
49 | // ImagePng generates a random rgba png image
50 | func (f *Faker) ImagePng(width int, height int) []byte { return imagePng(f, width, height) }
51 |
52 | func imagePng(f *Faker, width int, height int) []byte {
53 | buf := new(bytes.Buffer)
54 | png.Encode(buf, image(f, width, height))
55 | return buf.Bytes()
56 | }
57 |
58 | func addImageLookup() {
59 | AddFuncLookup("imagejpeg", Info{
60 | Display: "Image JPEG",
61 | Category: "image",
62 | Description: "Image file format known for its efficient compression and compatibility",
63 | Example: "file.jpeg - bytes",
64 | Output: "[]byte",
65 | ContentType: "image/jpeg",
66 | Params: []Param{
67 | {Field: "width", Display: "Width", Type: "int", Default: "500", Description: "Image width in px"},
68 | {Field: "height", Display: "Height", Type: "int", Default: "500", Description: "Image height in px"},
69 | },
70 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
71 | width, err := info.GetInt(m, "width")
72 | if err != nil {
73 | return nil, err
74 | }
75 | if width < 10 || width >= 1000 {
76 | return nil, errors.New("invalid image width, must be greater than 10, less than 1000")
77 | }
78 |
79 | height, err := info.GetInt(m, "height")
80 | if err != nil {
81 | return nil, err
82 | }
83 | if height < 10 || height >= 1000 {
84 | return nil, errors.New("invalid image height, must be greater than 10, less than 1000")
85 | }
86 |
87 | return imageJpeg(f, width, height), nil
88 | },
89 | })
90 |
91 | AddFuncLookup("imagepng", Info{
92 | Display: "Image PNG",
93 | Category: "image",
94 | Description: "Image file format known for its lossless compression and support for transparency",
95 | Example: "file.png - bytes",
96 | Output: "[]byte",
97 | ContentType: "image/png",
98 | Params: []Param{
99 | {Field: "width", Display: "Width", Type: "int", Default: "500", Description: "Image width in px"},
100 | {Field: "height", Display: "Height", Type: "int", Default: "500", Description: "Image height in px"},
101 | },
102 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
103 | width, err := info.GetInt(m, "width")
104 | if err != nil {
105 | return nil, err
106 | }
107 | if width < 10 || width >= 1000 {
108 | return nil, errors.New("invalid image width, must be greater than 10, less than 1000")
109 | }
110 |
111 | height, err := info.GetInt(m, "height")
112 | if err != nil {
113 | return nil, err
114 | }
115 | if height < 10 || height >= 1000 {
116 | return nil, errors.New("invalid image height, must be greater than 10, less than 1000")
117 | }
118 |
119 | return imagePng(f, width, height), nil
120 | },
121 | })
122 | }
123 |
--------------------------------------------------------------------------------
/languages.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | // Language will return a random language
4 | func Language() string { return language(GlobalFaker) }
5 |
6 | // Language will return a random language
7 | func (f *Faker) Language() string { return language(f) }
8 |
9 | func language(f *Faker) string { return getRandValue(f, []string{"language", "long"}) }
10 |
11 | // LanguageAbbreviation will return a random language abbreviation
12 | func LanguageAbbreviation() string { return languageAbbreviation(GlobalFaker) }
13 |
14 | // LanguageAbbreviation will return a random language abbreviation
15 | func (f *Faker) LanguageAbbreviation() string { return languageAbbreviation(f) }
16 |
17 | func languageAbbreviation(f *Faker) string { return getRandValue(f, []string{"language", "short"}) }
18 |
19 | // LanguageBCP will return a random language BCP (Best Current Practices)
20 | func LanguageBCP() string { return languageBCP(GlobalFaker) }
21 |
22 | // LanguageBCP will return a random language BCP (Best Current Practices)
23 | func (f *Faker) LanguageBCP() string { return languageBCP(f) }
24 |
25 | func languageBCP(f *Faker) string { return getRandValue(f, []string{"language", "bcp"}) }
26 |
27 | // ProgrammingLanguage will return a random programming language
28 | func ProgrammingLanguage() string { return programmingLanguage(GlobalFaker) }
29 |
30 | // ProgrammingLanguage will return a random programming language
31 | func (f *Faker) ProgrammingLanguage() string { return programmingLanguage(f) }
32 |
33 | func programmingLanguage(f *Faker) string {
34 | return getRandValue(f, []string{"language", "programming"})
35 | }
36 |
37 | func addLanguagesLookup() {
38 | AddFuncLookup("language", Info{
39 | Display: "Language",
40 | Category: "language",
41 | Description: "System of communication using symbols, words, and grammar to convey meaning between individuals",
42 | Example: "Kazakh",
43 | Output: "string",
44 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
45 | return language(f), nil
46 | },
47 | })
48 |
49 | AddFuncLookup("languageabbreviation", Info{
50 | Display: "Language Abbreviation",
51 | Category: "language",
52 | Description: "Shortened form of a language's name",
53 | Example: "kk",
54 | Output: "string",
55 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
56 | return languageAbbreviation(f), nil
57 | },
58 | })
59 |
60 | AddFuncLookup("languagebcp", Info{
61 | Display: "Language BCP",
62 | Category: "language",
63 | Description: "Set of guidelines and standards for identifying and representing languages in computing and internet protocols",
64 | Example: "en-US",
65 | Output: "string",
66 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
67 | return languageBCP(f), nil
68 | },
69 | })
70 |
71 | AddFuncLookup("programminglanguage", Info{
72 | Display: "Programming Language",
73 | Category: "language",
74 | Description: "Formal system of instructions used to create software and perform computational tasks",
75 | Example: "Go",
76 | Output: "string",
77 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
78 | return programmingLanguage(f), nil
79 | },
80 | })
81 | }
82 |
--------------------------------------------------------------------------------
/languages_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleLanguage() {
9 | Seed(11)
10 | fmt.Println(Language())
11 |
12 | // Output: Turkish
13 | }
14 |
15 | func ExampleFaker_Language() {
16 | f := New(11)
17 | fmt.Println(f.Language())
18 |
19 | // Output: Turkish
20 | }
21 |
22 | func BenchmarkLanguage(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Language()
25 | }
26 | }
27 |
28 | func ExampleLanguageAbbreviation() {
29 | Seed(11)
30 | fmt.Println(LanguageAbbreviation())
31 |
32 | // Output: tr
33 | }
34 |
35 | func ExampleFaker_LanguageAbbreviation() {
36 | f := New(11)
37 | fmt.Println(f.LanguageAbbreviation())
38 |
39 | // Output: tr
40 | }
41 |
42 | func BenchmarkLanguageAbbreviation(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | LanguageAbbreviation()
45 | }
46 | }
47 |
48 | func ExampleLanguageBCP() {
49 | Seed(11)
50 | fmt.Println(LanguageBCP())
51 |
52 | // Output: tr-TR
53 | }
54 |
55 | func ExampleFaker_LanguageBCP() {
56 | f := New(11)
57 | fmt.Println(f.LanguageBCP())
58 |
59 | // Output: tr-TR
60 | }
61 |
62 | func BenchmarkLanguageBCP(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | LanguageBCP()
65 | }
66 | }
67 |
68 | func ExampleProgrammingLanguage() {
69 | Seed(11)
70 | fmt.Println(ProgrammingLanguage())
71 |
72 | // Output: TELCOMP
73 | }
74 |
75 | func ExampleFaker_ProgrammingLanguage() {
76 | f := New(11)
77 | fmt.Println(f.ProgrammingLanguage())
78 |
79 | // Output: TELCOMP
80 | }
81 |
82 | func BenchmarkProgrammingLanguage(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | ProgrammingLanguage()
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/brianvoe/gofakeit/b3820daba293d107191129e516fb396e03a70a31/logo.png
--------------------------------------------------------------------------------
/lorem_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleLoremIpsumWord() {
9 | Seed(11)
10 | fmt.Println(LoremIpsumWord())
11 |
12 | // Output: eveniet
13 | }
14 |
15 | func ExampleFaker_LoremIpsumWord() {
16 | f := New(11)
17 | fmt.Println(f.LoremIpsumWord())
18 |
19 | // Output: eveniet
20 | }
21 |
22 | func BenchmarkLoremIpsumWord(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | LoremIpsumWord()
25 | }
26 | }
27 |
28 | func ExampleLoremIpsumSentence() {
29 | Seed(11)
30 | fmt.Println(LoremIpsumSentence(5))
31 |
32 | // Output: Eveniet vero velit velit non.
33 | }
34 |
35 | func ExampleFaker_LoremIpsumSentence() {
36 | f := New(11)
37 | fmt.Println(f.LoremIpsumSentence(5))
38 |
39 | // Output: Eveniet vero velit velit non.
40 | }
41 |
42 | func TestLoremIpsumSentence(t *testing.T) {
43 | for _, count := range []int{-100, -1, 0} {
44 | if LoremIpsumSentence(count) != "" {
45 | t.Errorf("result should be blank for %d words", count)
46 | }
47 | }
48 | }
49 |
50 | func BenchmarkLoremIpsumSentence(b *testing.B) {
51 | for i := 0; i < b.N; i++ {
52 | LoremIpsumSentence(10)
53 | }
54 | }
55 |
56 | func ExampleLoremIpsumParagraph() {
57 | Seed(11)
58 | fmt.Println(LoremIpsumParagraph(3, 5, 12, "\n"))
59 |
60 | // Output: Eveniet vero velit velit non incidunt est sed tenetur consequatur ut architecto. Quod non non et voluptas et esse quisquam ullam placeat molestiae laboriosam. Consequatur in perferendis molestiae quam voluptatem eaque quia facilis quo hic dignissimos. Architecto ut tenetur aut qui et optio id sint quae rerum labore. Quae deserunt quia mollitia id accusantium itaque nisi aut omnis occaecati repellendus.
61 | // Ad sunt neque placeat et qui saepe voluptatem blanditiis voluptatum possimus saepe. Velit distinctio quia quas cupiditate sequi dolorum delectus quia quo corrupti labore. Aut mollitia et aut eligendi blanditiis corrupti aut rem voluptatibus veritatis ut. Et ab voluptas delectus repellat eligendi qui eos blanditiis et et eos. Qui ipsum aut ut voluptate nulla officia qui earum repudiandae quidem officia.
62 | // Fugit esse beatae placeat nihil libero et sunt voluptas velit maiores voluptatem. Reiciendis quia dolor amet blanditiis labore eligendi fugit reiciendis modi est incidunt. Ut ut rerum odit sit voluptatem ipsam consequatur est incidunt aut quis. Non dolorem voluptatum pariatur esse eos blanditiis rem eos commodi accusamus occaecati. Qui voluptatem eos et tempora et id at voluptas suscipit magni cupiditate.
63 | }
64 |
65 | func ExampleFaker_LoremIpsumParagraph() {
66 | f := New(11)
67 | fmt.Println(f.LoremIpsumParagraph(3, 5, 12, "\n"))
68 |
69 | // Output: Eveniet vero velit velit non incidunt est sed tenetur consequatur ut architecto. Quod non non et voluptas et esse quisquam ullam placeat molestiae laboriosam. Consequatur in perferendis molestiae quam voluptatem eaque quia facilis quo hic dignissimos. Architecto ut tenetur aut qui et optio id sint quae rerum labore. Quae deserunt quia mollitia id accusantium itaque nisi aut omnis occaecati repellendus.
70 | // Ad sunt neque placeat et qui saepe voluptatem blanditiis voluptatum possimus saepe. Velit distinctio quia quas cupiditate sequi dolorum delectus quia quo corrupti labore. Aut mollitia et aut eligendi blanditiis corrupti aut rem voluptatibus veritatis ut. Et ab voluptas delectus repellat eligendi qui eos blanditiis et et eos. Qui ipsum aut ut voluptate nulla officia qui earum repudiandae quidem officia.
71 | // Fugit esse beatae placeat nihil libero et sunt voluptas velit maiores voluptatem. Reiciendis quia dolor amet blanditiis labore eligendi fugit reiciendis modi est incidunt. Ut ut rerum odit sit voluptatem ipsam consequatur est incidunt aut quis. Non dolorem voluptatum pariatur esse eos blanditiis rem eos commodi accusamus occaecati. Qui voluptatem eos et tempora et id at voluptas suscipit magni cupiditate.
72 | }
73 |
74 | func TestLoremIpsumParagraph(t *testing.T) {
75 | for _, count := range []struct{ parag, sent, words int }{
76 | {1, 1, 0},
77 | {1, 0, 1},
78 | {0, 1, 1},
79 | {1, 1, -100},
80 | {1, -100, 1},
81 | {-100, 1, 1},
82 | {0, 0, 0},
83 | } {
84 | if LoremIpsumParagraph(count.parag, count.sent, count.words, " ") != "" {
85 | t.Errorf("result should be blank for %v input", count)
86 | }
87 | }
88 | }
89 |
90 | func BenchmarkLoremIpsumParagraph(b *testing.B) {
91 | for i := 0; i < b.N; i++ {
92 | LoremIpsumParagraph(3, 5, 12, "\n")
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/movie.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | func MovieName() string { return movieName(GlobalFaker) }
4 |
5 | func (f *Faker) MovieName() string { return movieName(f) }
6 |
7 | func movieName(f *Faker) string { return getRandValue(f, []string{"movie", "name"}) }
8 |
9 | func MovieGenre() string { return movieGenre(GlobalFaker) }
10 |
11 | func (f *Faker) MovieGenre() string { return movieGenre(f) }
12 |
13 | func movieGenre(f *Faker) string { return getRandValue(f, []string{"movie", "genre"}) }
14 |
15 | type MovieInfo struct {
16 | Name string `json:"name" xml:"name"`
17 | Genre string `json:"genre" xml:"genre"`
18 | }
19 |
20 | func Movie() *MovieInfo { return movie(GlobalFaker) }
21 |
22 | func (f *Faker) Movie() *MovieInfo { return movie(f) }
23 |
24 | func movie(f *Faker) *MovieInfo {
25 | return &MovieInfo{
26 | Name: movieName(f),
27 | Genre: movieGenre(f),
28 | }
29 | }
30 |
31 | func addMovieLookup() {
32 | AddFuncLookup("movie", Info{
33 | Display: "Movie",
34 | Category: "movie",
35 | Description: "A story told through moving pictures and sound",
36 | Example: `{
37 | "name": "Psycho",
38 | "genre": "Mystery"
39 | }`,
40 | Output: "map[string]string",
41 | ContentType: "application/json",
42 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
43 | return movie(f), nil
44 | },
45 | })
46 |
47 | AddFuncLookup("moviename", Info{
48 | Display: "Movie Name",
49 | Category: "movie",
50 | Description: "Title or name of a specific film used for identification and reference",
51 | Example: "The Matrix",
52 | Output: "string",
53 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
54 | return movieName(f), nil
55 | },
56 | })
57 |
58 | AddFuncLookup("moviegenre", Info{
59 | Display: "Genre",
60 | Category: "movie",
61 | Description: "Category that classifies movies based on common themes, styles, and storytelling approaches",
62 | Example: "Action",
63 | Output: "string",
64 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
65 | return movieGenre(f), nil
66 | },
67 | })
68 | }
69 |
--------------------------------------------------------------------------------
/movie_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleMovie() {
9 | Seed(11)
10 | movie := Movie()
11 | fmt.Println(movie.Name)
12 | fmt.Println(movie.Genre)
13 |
14 | // Output: The Terminator
15 | // Sport
16 | }
17 |
18 | func ExampleFaker_Movie() {
19 | f := New(11)
20 | movie := f.Movie()
21 | fmt.Println(movie.Name)
22 | fmt.Println(movie.Genre)
23 |
24 | // Output: The Terminator
25 | // Sport
26 | }
27 |
28 | func BenchmarkMovie(b *testing.B) {
29 | for i := 0; i < b.N; i++ {
30 | Movie()
31 | }
32 | }
33 |
34 | func TestMovie(t *testing.T) {
35 | for i := 0; i < 100; i++ {
36 | Movie()
37 | }
38 | }
39 |
40 | func ExampleMovieName() {
41 | Seed(11)
42 | fmt.Println(MovieName())
43 |
44 | // Output: The Terminator
45 | }
46 |
47 | func ExampleFaker_MovieName() {
48 | f := New(11)
49 | fmt.Println(f.MovieName())
50 |
51 | // Output: The Terminator
52 | }
53 |
54 | func BenchmarkMovieName(b *testing.B) {
55 | for i := 0; i < b.N; i++ {
56 | MovieName()
57 | }
58 | }
59 |
60 | func ExampleMovieGenre() {
61 | Seed(11)
62 | fmt.Println(MovieGenre())
63 |
64 | // Output: Thriller
65 | }
66 |
67 | func ExampleFaker_MovieGenre() {
68 | f := New(11)
69 | fmt.Println(f.MovieGenre())
70 |
71 | // Output: Thriller
72 | }
73 |
74 | func BenchmarkMovieGenre(b *testing.B) {
75 | for i := 0; i < b.N; i++ {
76 | MovieGenre()
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/school.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | // School will generate a random School type
4 | func School() string { return school(GlobalFaker) }
5 |
6 | func (f *Faker) School() string { return school(f) }
7 |
8 | func school(f *Faker) string {
9 | return getRandValue(f, []string{"school", "name"}) + " " +
10 | getRandValue(f, []string{"school", "isPrivate"}) + " " +
11 | getRandValue(f, []string{"school", "type"})
12 | }
13 |
14 | func addSchoolLookup() {
15 | AddFuncLookup("school", Info{
16 | Display: "School",
17 | Category: "school",
18 | Description: "An institution for formal education and learning",
19 | Example: `Harborview State Academy`,
20 | Output: "string",
21 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
22 | return school(f), nil
23 | },
24 | })
25 | }
26 |
--------------------------------------------------------------------------------
/school_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleSchool() {
9 | Seed(11)
10 | fmt.Println(School())
11 |
12 | // Output: Hillside Private Academy
13 | }
14 |
15 | func ExampleFaker_School() {
16 | f := New(11)
17 | fmt.Println(f.School())
18 |
19 | // Output: Hillside Private Academy
20 | }
21 |
22 | func BenchmarkSchool(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | School()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/slice.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "reflect"
5 | )
6 |
7 | // Slice fills built-in types and exported fields of a struct with random data.
8 | func Slice(v any) { sliceFunc(GlobalFaker, v) }
9 |
10 | // Slice fills built-in types and exported fields of a struct with random data.
11 | func (f *Faker) Slice(v any) { sliceFunc(f, v) }
12 |
13 | func sliceFunc(f *Faker, v any) {
14 | r(f, reflect.TypeOf(v), reflect.ValueOf(v), "", -1)
15 | }
16 |
--------------------------------------------------------------------------------
/slice_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | )
6 |
7 | func ExampleSlice() {
8 | Seed(11)
9 |
10 | var S []string
11 | Slice(&S)
12 |
13 | I := make([]int8, 3)
14 | Slice(&I)
15 |
16 | fmt.Println(S)
17 | fmt.Println(I)
18 |
19 | // Output: [KKbMlbxqu mwwv WVlPmw AeAwVH Khrx DcxFeWk vChMCeKf BwRtnboOE mWluN]
20 | // [102 -7 -125]
21 | }
22 |
23 | func ExampleFaker_Slice() {
24 | f := New(11)
25 |
26 | var S []string
27 | f.Slice(&S)
28 |
29 | I := make([]int8, 3)
30 | f.Slice(&I)
31 |
32 | fmt.Println(S)
33 | fmt.Println(I)
34 |
35 | // Output: [KKbMlbxqu mwwv WVlPmw AeAwVH Khrx DcxFeWk vChMCeKf BwRtnboOE mWluN]
36 | // [102 -7 -125]
37 | }
38 |
39 | func ExampleSlice_struct() {
40 | Seed(11)
41 |
42 | type Basic struct {
43 | S string `fake:"{firstname}"`
44 | I int
45 | F float32
46 | }
47 |
48 | var B []Basic
49 | Slice(&B)
50 |
51 | fmt.Println(B)
52 |
53 | // Output: [{Russ 3680786209731553973 0.27238095} {Julius 4268594234476337060 0.0051180124} {Kaitlyn 8337306475187377941 0.118576884} {Steve 1365845625386394310 0.27625358} {Tomasa 7952567920265354269 0.648698} {Ernest 7933890822314871011 0.37052673} {Missouri 5542429450337529393 0.36615264} {Tiana 6292602578870227868 0.9382272} {Koby 229639691709918065 0.5914113}]
54 | }
55 |
56 | func ExampleFaker_Slice_struct() {
57 | f := New(11)
58 |
59 | type Basic struct {
60 | S string `fake:"{firstname}"`
61 | I int
62 | F float32
63 | }
64 |
65 | var B []Basic
66 | f.Slice(&B)
67 |
68 | fmt.Println(B)
69 |
70 | // Output: [{Russ 3680786209731553973 0.27238095} {Julius 4268594234476337060 0.0051180124} {Kaitlyn 8337306475187377941 0.118576884} {Steve 1365845625386394310 0.27625358} {Tomasa 7952567920265354269 0.648698} {Ernest 7933890822314871011 0.37052673} {Missouri 5542429450337529393 0.36615264} {Tiana 6292602578870227868 0.9382272} {Koby 229639691709918065 0.5914113}]
71 | }
72 |
--------------------------------------------------------------------------------
/song.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | func SongName() string { return songName(GlobalFaker) }
4 |
5 | func (f *Faker) SongName() string { return songName(f) }
6 |
7 | func songName(f *Faker) string { return getRandValue(f, []string{"song", "name"}) }
8 |
9 | func SongArtist() string { return songArtist(GlobalFaker) }
10 |
11 | func (f *Faker) SongArtist() string { return songArtist(f) }
12 |
13 | func songArtist(f *Faker) string { return getRandValue(f, []string{"song", "artist"}) }
14 |
15 | func SongGenre() string { return songGenre(GlobalFaker) }
16 |
17 | func (f *Faker) SongGenre() string { return songGenre(f) }
18 |
19 | func songGenre(f *Faker) string { return getRandValue(f, []string{"song", "genre"}) }
20 |
21 | type SongInfo struct {
22 | Name string `json:"name" xml:"name"`
23 | Artist string `json:"artist" xml:"artist"`
24 | Genre string `json:"genre" xml:"genre"`
25 | }
26 |
27 | func Song() *SongInfo { return song(GlobalFaker) }
28 |
29 | func (f *Faker) Song() *SongInfo { return song(f) }
30 |
31 | func song(f *Faker) *SongInfo {
32 | return &SongInfo{
33 | Name: songName(f),
34 | Artist: songArtist(f),
35 | Genre: songGenre(f),
36 | }
37 | }
38 |
39 | func addSongLookup() {
40 | AddFuncLookup("song", Info{
41 | Display: "Song",
42 | Category: "song",
43 | Description: "Song with a drum and horn instrumentation",
44 | Example: `{
45 | "name": "New Rules",
46 | "genre": "Tropical house"
47 | }`,
48 | Output: "map[string]string",
49 | ContentType: "application/json",
50 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
51 | return song(f), nil
52 | },
53 | })
54 |
55 | AddFuncLookup("songname", Info{
56 | Display: "Song Name",
57 | Category: "song",
58 | Description: "Title or name of a specific song used for identification and reference",
59 | Example: "New Rules",
60 | Output: "string",
61 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
62 | return songName(f), nil
63 | },
64 | })
65 |
66 | AddFuncLookup("songartist", Info{
67 | Display: "Song Artist",
68 | Category: "song",
69 | Description: "The artist of maker of song",
70 | Example: "Dua Lipa",
71 | Output: "string",
72 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
73 | return songArtist(f), nil
74 | },
75 | })
76 |
77 | AddFuncLookup("songgenre", Info{
78 | Display: "Genre",
79 | Category: "song",
80 | Description: "Category that classifies song based on common themes, styles, and storytelling approaches",
81 | Example: "Action",
82 | Output: "string",
83 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
84 | return songGenre(f), nil
85 | },
86 | })
87 | }
88 |
--------------------------------------------------------------------------------
/song_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleSong() {
9 | Seed(11)
10 | song := Song()
11 | fmt.Println(song.Name)
12 | fmt.Println(song.Artist)
13 | fmt.Println(song.Genre)
14 |
15 | // Output: What Was I Made For?
16 | // Taylor Swift
17 | // Country
18 | }
19 |
20 | func ExampleFaker_Song() {
21 | f := New(11)
22 | song := f.Song()
23 | fmt.Println(song.Name)
24 | fmt.Println(song.Artist)
25 | fmt.Println(song.Genre)
26 |
27 | // Output: What Was I Made For?
28 | // Taylor Swift
29 | // Country
30 | }
31 |
32 | func BenchmarkSong(b *testing.B) {
33 | for i := 0; i < b.N; i++ {
34 | Song()
35 | }
36 | }
37 |
38 | func TestSong(t *testing.T) {
39 | for i := 0; i < 100; i++ {
40 | Song()
41 | }
42 | }
43 |
44 | func ExampleSongName() {
45 | Seed(11)
46 | fmt.Println(SongName())
47 |
48 | // Output: What Was I Made For?
49 | }
50 |
51 | func ExampleFaker_SongName() {
52 | f := New(11)
53 | fmt.Println(f.SongName())
54 |
55 | // Output: What Was I Made For?
56 | }
57 |
58 | func BenchmarkSongName(b *testing.B) {
59 | for i := 0; i < b.N; i++ {
60 | SongName()
61 | }
62 | }
63 |
64 | func ExampleSongArtist() {
65 | Seed(11)
66 | fmt.Println(SongArtist())
67 |
68 | // Output: The Jacksons
69 | }
70 |
71 | func ExampleFaker_SongArtist() {
72 | f := New(11)
73 | fmt.Println(f.SongArtist())
74 |
75 | // Output: The Jacksons
76 | }
77 |
78 | func BenchmarkSongArtist(b *testing.B) {
79 | for i := 0; i < b.N; i++ {
80 | SongArtist()
81 | }
82 | }
83 |
84 | func ExampleSongGenre() {
85 | Seed(11)
86 | fmt.Println(SongGenre())
87 |
88 | // Output: Synthwave
89 | }
90 |
91 | func ExampleFaker_SongGenre() {
92 | f := New(11)
93 | fmt.Println(f.SongGenre())
94 |
95 | // Output: Synthwave
96 | }
97 |
98 | func BenchmarkSongGenre(b *testing.B) {
99 | for i := 0; i < b.N; i++ {
100 | SongGenre()
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/source/BENCHMARKS.md:
--------------------------------------------------------------------------------
1 | go test -bench=. -benchmem \
2 | goos: darwin \
3 | goarch: amd64 \
4 | pkg: github.com/brianvoe/gofakeit/v7 \
5 | cpu: Apple M1 Max \
6 | Table generated with tablesgenerator.com/markdown_tables File->Paste table data
7 |
8 | | Benchmark | Iterations| Time/Iter | Bytes | Allocations |
9 | |---------------------|-----------|-------------|--------|-------------|
10 | | BenchmarkPCG-10 | 251946703 | 4.763 ns/op | 0 B/op | 0 allocs/op |
11 | | BenchmarkChaCha8-10 | 228052915 | 5.262 ns/op | 0 B/op | 0 allocs/op |
12 | | BenchmarkJSF-10 | 323858558 | 3.712 ns/op | 0 B/op | 0 allocs/op |
13 | | BenchmarkSFC-10 | 394809136 | 3.035 ns/op | 0 B/op | 0 allocs/op |
14 | | BenchmarkOld-10 | 207714157 | 5.733 ns/op | 0 B/op | 0 allocs/op |
15 | | BenchmarkDumb-10 | 458967214 | 2.611 ns/op | 0 B/op | 0 allocs/op |
16 | | BenchmarkCrypto-10 | 15747936 | 77.15 ns/op | 0 B/op | 0 allocs/op |
--------------------------------------------------------------------------------
/source/README.md:
--------------------------------------------------------------------------------
1 | # Random Number Generators Collection
2 |
3 | This repository contains a collection of random number generators (RNGs) implemented in Go, designed to cater to a wide range of applications, from cryptographic operations to testing environments. Each RNG in the collection offers distinct features and performance characteristics, making it suitable for various use cases, including those requiring cryptographic security.
4 |
5 | ## Generators
6 |
7 | ### Crypto
8 |
9 | - **Description**: Utilizes Go's `crypto/rand` package to provide cryptographically secure random numbers, suitable for security-sensitive applications.
10 | - **Usage**:
11 | ```go
12 | source := NewCryptoSource()
13 | number := source.Uint64()
14 | ```
15 |
16 | ### JSF (Jenkins Small Fast)
17 |
18 | - **Description**: An implementation of the Jenkins Small Fast hash function for efficient pseudo-random number generation, balancing speed and randomness quality for general use.
19 | - **Usage**:
20 | ```go
21 | source := NewJSFSource(seed)
22 | number := source.Uint64()
23 | ```
24 |
25 | ### SFC (Simple Fast Counter)
26 |
27 | - **Description**: Based on the Simple Fast Counter algorithm, this source offers rapid number generation with satisfactory randomness properties, ideal for simulations and non-cryptographic applications.
28 | - **Usage**:
29 | ```go
30 | source := NewSFCSource(seed)
31 | number := source.Uint64()
32 | ```
33 |
34 | ### Dumb
35 |
36 | - **Description**: A deterministic generator designed primarily for testing, providing predictable output for scenarios where consistent results are more beneficial than high-quality randomness.
37 | - **Usage**:
38 | ```go
39 | source := NewDumb(seed)
40 | number := source.Uint64()
41 | ```
42 |
43 | ## Installation
44 |
45 | To use these RNGs in your Go project, import the package as follows:
46 |
47 | ```go
48 | import "github.com/yourusername/randsource"
49 | ```
50 |
51 | Replace `yourusername` with your GitHub username or organization name where the repository is hosted.
52 |
53 | ## Usage
54 |
55 | After importing the package, initialize the desired RNG with or without a seed (as applicable) and use the `Uint64` method to generate random numbers. See the usage examples under each generator's description for more details.
56 |
57 | ## Benchmarks
58 |
59 | Performance benchmarks for each RNG are provided to help you choose the right generator for your application. These benchmarks cover various aspects, including speed and randomness quality.
60 |
61 | For detailed benchmark results, see the [Benchmarks](https://github.com/brianvoe/gofakeit/blob/master/source/BENCHMARKS.md) file.
62 |
63 | ## Contributing
64 |
65 | We welcome contributions and suggestions! Please open an issue or submit a pull request with your improvements.
66 |
--------------------------------------------------------------------------------
/source/crypto.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | import (
4 | "crypto/rand"
5 | "encoding/binary"
6 | )
7 |
8 | // Package source implements a cryptographically secure pseudo-random number generator (CSPRNG)
9 | // using Go's crypto/rand. The Crypto type is designed for generating high-quality random
10 | // uint64 values, suitable for cryptographic applications like secure token generation,
11 | // cryptographic key creation, and other security-sensitive operations. It offers optional
12 | // thread safety through a locking mechanism, making it suitable for concurrent usage.
13 |
14 | // Pros:
15 | // - Provides cryptographically secure randomness, suitable for security-sensitive applications.
16 | // - Optional thread safety with locking, enabling safe concurrent access.
17 |
18 | // Cons:
19 | // - Locking mechanism, when enabled, may introduce performance overhead.
20 | // - Does not utilize a seed, as it leverages the system's cryptographic RNG, which may be a
21 | // limitation in scenarios where deterministic pseudo-randomness is desired.
22 |
23 | type Crypto struct {
24 | buffer [64]byte // Buffer to hold a block of random data
25 | offset int // Current offset in the buffer
26 | }
27 |
28 | // NewCrypto creates a new instance of Crypto.
29 | func NewCrypto() *Crypto {
30 | return &Crypto{
31 | buffer: [64]byte{}, // Initialize buffer with zeros
32 | offset: 64, // Set offset to the end of the buffer to trigger a refill on the first call
33 | }
34 | }
35 |
36 | // refillBuffer fills the buffer with random data from crypto/rand.
37 | func (s *Crypto) refillBuffer() {
38 | if _, err := rand.Read(s.buffer[:]); err != nil {
39 | panic("crypto/rand failed: " + err.Error()) // Handle the error appropriately for your application
40 | }
41 | s.offset = 0 // Reset offset after refilling
42 | }
43 |
44 | // Uint64 generates a pseudo-random 64-bit value using crypto/rand, served from a buffered block of data.
45 | func (s *Crypto) Uint64() uint64 {
46 | if s.offset+8 > len(s.buffer) { // Check if we need to refill the buffer
47 | s.refillBuffer()
48 | }
49 |
50 | // Extract a uint64 value from the current position in the buffer
51 | val := binary.BigEndian.Uint64(s.buffer[s.offset:])
52 | s.offset += 8 // Move the offset for the next call
53 |
54 | return val
55 | }
56 |
--------------------------------------------------------------------------------
/source/crypto_test.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | import "testing"
4 |
5 | func TestCrypto(t *testing.T) {
6 | crypto := NewCrypto()
7 |
8 | // test for duplicates
9 | m := make(map[uint64]bool)
10 | for i := 0; i < 100000; i++ {
11 | v := crypto.Uint64()
12 | if m[v] {
13 | t.Errorf("Duplicate value: %v", v)
14 | }
15 | m[v] = true
16 | }
17 | }
18 |
19 | func BenchmarkCrypto(b *testing.B) {
20 | crypto := NewCrypto()
21 |
22 | for i := 0; i < b.N; i++ {
23 | crypto.Uint64()
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/source/dumb.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | import "time"
4 |
5 | // Dumb is a deterministic pseudo-random number generator designed specifically for testing purposes.
6 | // It offers predictable sequences of numbers based on the provided seed, making it ideal for scenarios
7 | // where consistent and reproducible test results are critical. By default, if initialized with a seed of 0,
8 | // Dumb uses the current timestamp to generate a starting point, ensuring some level of variability between runs.
9 |
10 | // Pros:
11 | // - Predictability: Ensures reproducible outcomes in tests by providing a consistent sequence of numbers for a given seed.
12 | // - Simplicity: Easy to understand and integrate into testing frameworks, with minimal overhead.
13 | // - Default Variability: Uses the current timestamp as the default seed, providing variability across different test runs when no seed is specified.
14 |
15 | // Cons:
16 | // - Not Suitable for Production: Lacks the randomness quality required for production-level cryptographic or statistical applications.
17 | // - Limited Randomness: The simple incrementation approach does not simulate the complexity of real-world random number generation.
18 |
19 | // Dumb is a simplistic generator for predictable testing.
20 | type Dumb struct {
21 | state uint64
22 | }
23 |
24 | // NewDumb initializes a Dumb generator.
25 | // If the seed is 0, initializes with the current timestamp.
26 | func NewDumb(seed uint64) *Dumb {
27 | d := &Dumb{}
28 | d.Seed(seed)
29 | return d
30 | }
31 |
32 | // Seed sets the generator's state. If the seed is 0, it uses the current timestamp as the seed.
33 | func (d *Dumb) Seed(seed uint64) {
34 | if seed == 0 {
35 | seed = uint64(time.Now().UnixNano())
36 | }
37 | d.state = seed
38 | }
39 |
40 | // Uint64 returns the next number in the sequence, incrementing the state.
41 | func (d *Dumb) Uint64() uint64 {
42 | d.state += 1
43 | return d.state
44 | }
45 |
--------------------------------------------------------------------------------
/source/dumb_test.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | import "testing"
4 |
5 | func TestDumb(t *testing.T) {
6 | dumb := NewDumb(0)
7 | dumb.Seed(0)
8 |
9 | // test for duplicates
10 | m := make(map[uint64]bool)
11 | for i := 0; i < 10000; i++ {
12 | v := dumb.Uint64()
13 | if m[v] {
14 | t.Errorf("Duplicate value: %v", v)
15 | }
16 | m[v] = true
17 | }
18 | }
19 |
20 | func BenchmarkDumb(b *testing.B) {
21 | dumb := NewDumb(0)
22 |
23 | for i := 0; i < b.N; i++ {
24 | dumb.Uint64()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/source/jsf.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | // The JSF(Jenkins Small Fast) pseudo-random number generator.
4 | // Developed by Bob Jenkins, JSF is known for its speed and efficiency, making it suitable
5 | // for applications requiring fast, non-cryptographic quality random numbers. This implementation
6 | // offers seamless integration with Go's math/rand package and includes an improved seeding mechanism.
7 |
8 | // Pros:
9 | // - Fast and efficient, ideal for high-performance requirements.
10 | // - Good randomness quality for non-cryptographic applications.
11 | // - Small state size and simple operations, ensuring a minimal memory footprint.
12 |
13 | // Cons:
14 | // - Not suitable for cryptographic purposes due to its non-cryptographic security level.
15 | // - Quality of randomness may not match that of more complex algorithms.
16 |
17 | type JSF struct {
18 | a, b, c, d uint32
19 | }
20 |
21 | // NewJSF creates and returns a new JSF pseudo-random number generator.
22 | func NewJSF(seed uint64) *JSF {
23 | jsf := &JSF{}
24 | jsf.Seed(seed)
25 | return jsf
26 | }
27 |
28 | // Seed sets the seed of the JSF with an improved seeding mechanism.
29 | func (jsf *JSF) Seed(seed uint64) {
30 | // Use the seed to derive initial values for a, b, c, d with better distribution
31 | // Splitting the 64-bit seed into parts and using different operations to diversify
32 | s1 := uint32(seed)
33 | s2 := uint32(seed >> 32)
34 | jsf.a = 0xf1ea5eed
35 | jsf.b = s1 ^ jsf.a
36 | jsf.c = s2 ^ jsf.b
37 | jsf.d = s1
38 | }
39 |
40 | // Uint64 generates a pseudo-random 64-bit value using the improved JSF algorithm.
41 | func (jsf *JSF) Uint64() uint64 {
42 | e := jsf.a - (jsf.b<<27 | jsf.b>>(32-27))
43 | f := jsf.b ^ (jsf.c << 17)
44 | jsf.c += jsf.d
45 | jsf.d += e
46 | jsf.a = jsf.b + f
47 | jsf.b = jsf.c + e
48 | jsf.c = f + jsf.a
49 | return uint64(jsf.d)<<32 | uint64(jsf.a)
50 | }
51 |
--------------------------------------------------------------------------------
/source/jsf_test.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | import "testing"
4 |
5 | func TestJSF(t *testing.T) {
6 | jsf := NewJSF(0)
7 | jsf.Seed(0)
8 |
9 | // test for duplicates
10 | m := make(map[uint64]bool)
11 | for i := 0; i < 10000; i++ {
12 | v := jsf.Uint64()
13 | if m[v] {
14 | t.Errorf("Duplicate value: %v", v)
15 | }
16 | m[v] = true
17 | }
18 | }
19 |
20 | func BenchmarkJSF(b *testing.B) {
21 | jsf := NewJSF(0)
22 |
23 | for i := 0; i < b.N; i++ {
24 | jsf.Uint64()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/source/others_test.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | import (
4 | "math/rand/v2"
5 | "testing"
6 | )
7 |
8 | func BenchmarkChaCha8(b *testing.B) {
9 | chacha := rand.NewChaCha8([32]byte{0, 1, 2, 3, 4, 5})
10 |
11 | for i := 0; i < b.N; i++ {
12 | chacha.Uint64()
13 | }
14 | }
15 |
16 | func BenchmarkPCG(b *testing.B) {
17 | pcg := rand.NewPCG(0, 0)
18 |
19 | for i := 0; i < b.N; i++ {
20 | pcg.Uint64()
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/source/sfc.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | // The SFC(Simple Fast Counter) algorithm is designed for fast and efficient generation of pseudo-random numbers,
4 | // utilizing arithmetic and bitwise operations across state variables and a counter to ensure
5 | // good randomness quality. It is particularly well-suited for applications requiring rapid
6 | // number generation without the need for cryptographic security.
7 |
8 | // Pros:
9 | // - High efficiency and speed, ideal for performance-sensitive applications.
10 | // - Simple to implement and maintain, with minimal computational overhead.
11 | // - Offers a balance between speed and randomness quality, suitable for a wide range of uses.
12 |
13 | // Cons:
14 | // - Not designed for cryptographic applications due to its level of randomness.
15 | // - Initial seeding mechanism is basic; may require enhancement for more complex use cases.
16 |
17 | type SFC struct {
18 | a, b, c, counter uint64
19 | }
20 |
21 | // NewSFC creates and returns a new SFC pseudo-random number generator seeded with a given seed.
22 | func NewSFC(seed uint64) *SFC {
23 | s := &SFC{}
24 | s.Seed(seed)
25 | return s
26 | }
27 |
28 | // Seed sets the seed of the SFC. This implementation can be enhanced to
29 | // provide a more distributed seeding process across the state variables.
30 | func (s *SFC) Seed(seed uint64) {
31 | s.a = seed
32 | s.b = seed
33 | s.c = seed
34 | s.counter = 1 // Reset counter with new seed
35 | }
36 |
37 | // Uint64 generates a pseudo-random 64-bit value using the SFC algorithm.
38 | func (s *SFC) Uint64() uint64 {
39 | s.a += s.b + s.counter
40 | s.b ^= s.c
41 | s.c -= s.a
42 | s.counter++
43 | return s.c + s.b
44 | }
45 |
--------------------------------------------------------------------------------
/source/sfc_test.go:
--------------------------------------------------------------------------------
1 | package source
2 |
3 | import "testing"
4 |
5 | func TestSFC(t *testing.T) {
6 | sfc := NewSFC(0)
7 | sfc.Seed(0)
8 |
9 | // test for duplicates
10 | m := make(map[uint64]bool)
11 | for i := 0; i < 10000; i++ {
12 | v := sfc.Uint64()
13 | if m[v] {
14 | t.Errorf("Duplicate value: %v", v)
15 | }
16 | m[v] = true
17 | }
18 | }
19 |
20 | func BenchmarkSFC(b *testing.B) {
21 | sfc := NewSFC(0)
22 |
23 | for i := 0; i < b.N; i++ {
24 | sfc.Uint64()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/weighted.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "errors"
5 | )
6 |
7 | // Weighted will take in an array of options and weights and return a random selection based upon its indexed weight
8 | func Weighted(options []any, weights []float32) (any, error) {
9 | return weighted(GlobalFaker, options, weights)
10 | }
11 |
12 | // Weighted will take in an array of options and weights and return a random selection based upon its indexed weight
13 | func (f *Faker) Weighted(options []any, weights []float32) (any, error) {
14 | return weighted(f, options, weights)
15 | }
16 |
17 | // Weighted will take in an array of options and weights and return a random selection based upon its indexed weight
18 | func weighted(f *Faker, options []any, weights []float32) (any, error) {
19 | ol := len(options)
20 | wl := len(weights)
21 |
22 | // If options length is 1 just return it back
23 | if ol == 1 {
24 | return options[0], nil
25 | }
26 |
27 | // Make sure they are passing in options
28 | if ol == 0 {
29 | return nil, errors.New("didnt pass options")
30 | }
31 |
32 | // Make sure they are passing in weights
33 | if wl == 0 {
34 | return nil, errors.New("didnt pass weights")
35 | }
36 |
37 | // Make sure they are passing in the same length
38 | if ol != wl {
39 | return nil, errors.New("options and weights need to be the same length")
40 | }
41 |
42 | // Compute the discrete cumulative density from the sum of the weights
43 | cdf := make([]float32, wl)
44 | var sumOfWeights float32 = 0.0
45 | for i, weight := range weights {
46 | if i > 0 {
47 | cdf[i] = cdf[i-1] + weight
48 | sumOfWeights += weight
49 | continue
50 | }
51 |
52 | cdf[i] = weight
53 | sumOfWeights += weight
54 | }
55 |
56 | // Get rand value from a multple of sumOfWeights
57 | randSumOfWeights := f.Float32() * sumOfWeights
58 |
59 | var l int = 0
60 | var h int = wl - 1
61 | for l <= h {
62 | m := l + (h-l)/2
63 | if randSumOfWeights <= cdf[m] {
64 | if m == 0 || (m > 0 && randSumOfWeights > cdf[m-1]) {
65 | return options[m], nil
66 | }
67 | h = m - 1
68 | } else {
69 | l = m + 1
70 | }
71 | }
72 |
73 | return nil, errors.New("end of function")
74 | }
75 |
76 | func addWeightedLookup() {
77 | AddFuncLookup("weighted", Info{
78 | Display: "Weighted",
79 | Category: "misc",
80 | Description: "Randomly select a given option based upon an equal amount of weights",
81 | Example: "[hello, 2, 6.9],[1, 2, 3] => 6.9",
82 | Output: "any",
83 | Params: []Param{
84 | {Field: "options", Display: "Options", Type: "[]string", Description: "Array of any values"},
85 | {Field: "weights", Display: "Weights", Type: "[]float", Description: "Array of weights"},
86 | },
87 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
88 | options, err := info.GetStringArray(m, "options")
89 | if err != nil {
90 | return nil, err
91 | }
92 |
93 | weights, err := info.GetFloat32Array(m, "weights")
94 | if err != nil {
95 | return nil, err
96 | }
97 |
98 | optionsInterface := make([]any, len(options))
99 | for i, o := range options {
100 | optionsInterface[i] = o
101 | }
102 |
103 | return weighted(f, optionsInterface, weights)
104 | },
105 | })
106 | }
107 |
--------------------------------------------------------------------------------
/weighted_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleWeighted() {
9 | Seed(11)
10 |
11 | options := []any{"hello", 2, 6.9}
12 | weights := []float32{1, 2, 3}
13 | option, _ := Weighted(options, weights)
14 |
15 | fmt.Println(option)
16 |
17 | // Output: 2
18 | }
19 |
20 | func TestWeighted(t *testing.T) {
21 | percOfValue := func(options []any, option any) float32 {
22 | var count float32 = 0
23 | for _, o := range options {
24 | if option == o {
25 | count++
26 | }
27 | }
28 |
29 | return (count / float32(len(options))) * 100
30 | }
31 |
32 | Seed(11)
33 | options := []any{"hello", 2, 6.9}
34 | weights := []float32{1, 2, 3}
35 |
36 | foundOptions := []any{}
37 | for i := 0; i < 100000; i++ {
38 | o, _ := Weighted(options, weights)
39 | foundOptions = append(foundOptions, o)
40 | }
41 |
42 | perc := percOfValue(foundOptions, "hello")
43 | if perc < 14 || perc > 18 {
44 | t.Error("hello was not in the bounds of expected range")
45 | }
46 | perc = percOfValue(foundOptions, 2)
47 | if perc < 30 || perc > 35 {
48 | t.Error("2 was not in the bounds of expected range")
49 | }
50 | perc = percOfValue(foundOptions, 6.9)
51 | if perc < 48 || perc > 52 {
52 | t.Error("6.9 was not in the bounds of expected range")
53 | }
54 | }
55 |
56 | func TestWeightedStruct(t *testing.T) {
57 | type weighted struct {
58 | S string `fake:"{weighted:[hello, 2, 6.9],[1, 2, 3]}"`
59 | }
60 |
61 | Seed(11)
62 |
63 | var weight weighted
64 | Struct(&weight)
65 |
66 | // Make sure it is one of the options
67 | if weight.S != "hello" && weight.S != "2" && weight.S != "6.9" {
68 | t.Error("Weighted did not return one of the options")
69 | }
70 | }
71 |
72 | func BenchmarkWeighted(b *testing.B) {
73 | options := []any{"hello", 2, 6.9}
74 | weights := []float32{1, 2, 3}
75 |
76 | Seed(11)
77 | for i := 0; i < b.N; i++ {
78 | Weighted(options, weights)
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/word_adjective_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleAdjective() {
9 | Seed(11)
10 | fmt.Println(Adjective())
11 |
12 | // Output: none
13 | }
14 |
15 | func ExampleFaker_Adjective() {
16 | f := New(11)
17 | fmt.Println(f.Adjective())
18 |
19 | // Output: none
20 | }
21 |
22 | func BenchmarkAdjective(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Adjective()
25 | }
26 | }
27 |
28 | func ExampleAdjectiveDescriptive() {
29 | Seed(11)
30 | fmt.Println(AdjectiveDescriptive())
31 |
32 | // Output: tired
33 | }
34 |
35 | func ExampleFaker_AdjectiveDescriptive() {
36 | f := New(11)
37 | fmt.Println(f.AdjectiveDescriptive())
38 |
39 | // Output: tired
40 | }
41 |
42 | func BenchmarkAdjectiveDescriptive(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | AdjectiveDescriptive()
45 | }
46 | }
47 |
48 | func ExampleAdjectiveQuantitative() {
49 | Seed(11)
50 | fmt.Println(AdjectiveQuantitative())
51 |
52 | // Output: sparse
53 | }
54 |
55 | func ExampleFaker_AdjectiveQuantitative() {
56 | f := New(11)
57 | fmt.Println(f.AdjectiveQuantitative())
58 |
59 | // Output: sparse
60 | }
61 |
62 | func BenchmarkAdjectiveQuantitative(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | AdjectiveQuantitative()
65 | }
66 | }
67 |
68 | func ExampleAdjectiveProper() {
69 | Seed(11)
70 | fmt.Println(AdjectiveProper())
71 |
72 | // Output: Swiss
73 | }
74 |
75 | func ExampleFaker_AdjectiveProper() {
76 | f := New(11)
77 | fmt.Println(f.AdjectiveProper())
78 |
79 | // Output: Swiss
80 | }
81 |
82 | func BenchmarkAdjectiveProper(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | AdjectiveProper()
85 | }
86 | }
87 |
88 | func ExampleAdjectiveDemonstrative() {
89 | Seed(11)
90 | fmt.Println(AdjectiveDemonstrative())
91 |
92 | // Output: it
93 | }
94 |
95 | func ExampleFaker_AdjectiveDemonstrative() {
96 | f := New(11)
97 | fmt.Println(f.AdjectiveDemonstrative())
98 |
99 | // Output: it
100 | }
101 |
102 | func BenchmarkAdjectiveDemonstrative(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | AdjectiveDemonstrative()
105 | }
106 | }
107 |
108 | func ExampleAdjectivePossessive() {
109 | Seed(11)
110 | fmt.Println(AdjectivePossessive())
111 |
112 | // Output: their
113 | }
114 |
115 | func ExampleFaker_AdjectivePossessive() {
116 | f := New(11)
117 | fmt.Println(f.AdjectivePossessive())
118 |
119 | // Output: their
120 | }
121 |
122 | func BenchmarkAdjectivePossessive(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | AdjectivePossessive()
125 | }
126 | }
127 |
128 | func ExampleAdjectiveInterrogative() {
129 | Seed(11)
130 | fmt.Println(AdjectiveInterrogative())
131 |
132 | // Output: which
133 | }
134 |
135 | func ExampleFaker_AdjectiveInterrogative() {
136 | f := New(11)
137 | fmt.Println(f.AdjectiveInterrogative())
138 |
139 | // Output: which
140 | }
141 |
142 | func BenchmarkAdjectiveInterrogative(b *testing.B) {
143 | for i := 0; i < b.N; i++ {
144 | AdjectiveInterrogative()
145 | }
146 | }
147 |
148 | func ExampleAdjectiveIndefinite() {
149 | Seed(11)
150 | fmt.Println(AdjectiveIndefinite())
151 |
152 | // Output: several
153 | }
154 |
155 | func ExampleFaker_AdjectiveIndefinite() {
156 | f := New(11)
157 | fmt.Println(f.AdjectiveIndefinite())
158 |
159 | // Output: several
160 | }
161 |
162 | func BenchmarkAdjectiveIndefinite(b *testing.B) {
163 | for i := 0; i < b.N; i++ {
164 | AdjectiveIndefinite()
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/word_adverb_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleAdverb() {
9 | Seed(11)
10 | fmt.Println(Adverb())
11 |
12 | // Output: ever
13 | }
14 |
15 | func ExampleFaker_Adverb() {
16 | f := New(11)
17 | fmt.Println(f.Adverb())
18 |
19 | // Output: ever
20 | }
21 |
22 | func BenchmarkAdverb(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Adverb()
25 | }
26 | }
27 |
28 | func ExampleAdverbManner() {
29 | Seed(11)
30 | fmt.Println(AdverbManner())
31 |
32 | // Output: tensely
33 | }
34 |
35 | func ExampleFaker_AdverbManner() {
36 | f := New(11)
37 | fmt.Println(f.AdverbManner())
38 |
39 | // Output: tensely
40 | }
41 |
42 | func BenchmarkAdverbManner(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | AdverbManner()
45 | }
46 | }
47 |
48 | func ExampleAdverbDegree() {
49 | Seed(11)
50 | fmt.Println(AdverbDegree())
51 |
52 | // Output: too
53 | }
54 |
55 | func ExampleFaker_AdverbDegree() {
56 | f := New(11)
57 | fmt.Println(f.AdverbDegree())
58 |
59 | // Output: too
60 | }
61 |
62 | func BenchmarkAdverbDegree(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | AdverbDegree()
65 | }
66 | }
67 |
68 | func ExampleAdverbPlace() {
69 | Seed(11)
70 | fmt.Println(AdverbPlace())
71 |
72 | // Output: under
73 | }
74 |
75 | func ExampleFaker_AdverbPlace() {
76 | f := New(11)
77 | fmt.Println(f.AdverbPlace())
78 |
79 | // Output: under
80 | }
81 |
82 | func BenchmarkAdverbPlace(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | AdverbPlace()
85 | }
86 | }
87 |
88 | func ExampleAdverbTimeDefinite() {
89 | Seed(11)
90 | fmt.Println(AdverbTimeDefinite())
91 |
92 | // Output: yesterday
93 | }
94 |
95 | func ExampleFaker_AdverbTimeDefinite() {
96 | f := New(11)
97 | fmt.Println(f.AdverbTimeDefinite())
98 |
99 | // Output: yesterday
100 | }
101 |
102 | func BenchmarkAdverbTimeDefinite(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | AdverbTimeDefinite()
105 | }
106 | }
107 |
108 | func ExampleAdverbTimeIndefinite() {
109 | Seed(11)
110 | fmt.Println(AdverbTimeIndefinite())
111 |
112 | // Output: soon
113 | }
114 |
115 | func ExampleFaker_AdverbTimeIndefinite() {
116 | f := New(11)
117 | fmt.Println(f.AdverbTimeIndefinite())
118 |
119 | // Output: soon
120 | }
121 |
122 | func BenchmarkAdverbTimeIndefinite(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | AdverbTimeIndefinite()
125 | }
126 | }
127 |
128 | func ExampleAdverbFrequencyDefinite() {
129 | Seed(11)
130 | fmt.Println(AdverbFrequencyDefinite())
131 |
132 | // Output: yearly
133 | }
134 |
135 | func ExampleFaker_AdverbFrequencyDefinite() {
136 | f := New(11)
137 | fmt.Println(f.AdverbFrequencyDefinite())
138 |
139 | // Output: yearly
140 | }
141 |
142 | func BenchmarkAdverbFrequencyDefinite(b *testing.B) {
143 | for i := 0; i < b.N; i++ {
144 | AdverbFrequencyDefinite()
145 | }
146 | }
147 |
148 | func ExampleAdverbFrequencyIndefinite() {
149 | Seed(11)
150 | fmt.Println(AdverbFrequencyIndefinite())
151 |
152 | // Output: generally
153 | }
154 |
155 | func ExampleFaker_AdverbFrequencyIndefinite() {
156 | f := New(11)
157 | fmt.Println(f.AdverbFrequencyIndefinite())
158 |
159 | // Output: generally
160 | }
161 |
162 | func BenchmarkAdverbFrequencyIndefinite(b *testing.B) {
163 | for i := 0; i < b.N; i++ {
164 | AdverbFrequencyIndefinite()
165 | }
166 | }
167 |
--------------------------------------------------------------------------------
/word_comment.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "strings"
5 | )
6 |
7 | // Comment will generate a random statement or remark expressing an opinion, observation, or reaction
8 | func Comment() string { return comment(GlobalFaker) }
9 |
10 | // Comment will generate a random statement or remark expressing an opinion, observation, or reaction
11 | func (f *Faker) Comment() string { return comment(f) }
12 |
13 | func comment(f *Faker) string {
14 | structures := [][]string{
15 | {"interjection", "adjective", "noun", "verb", "adverb"},
16 | {"noun", "verb", "preposition", "determiner", "adjective", "noun"},
17 | {"noun", "verb", "adverb"},
18 | {"adjective", "noun", "verb"},
19 | {"noun", "verb", "preposition", "noun"},
20 | }
21 |
22 | // Randomly select a structure
23 | structure := structures[number(f, 0, len(structures)-1)]
24 |
25 | // Build the sentence
26 | var commentParts []string
27 | for _, wordType := range structure {
28 | switch wordType {
29 | case "noun":
30 | commentParts = append(commentParts, noun(f))
31 | case "verb":
32 | commentParts = append(commentParts, verb(f))
33 | case "adjective":
34 | commentParts = append(commentParts, adjective(f))
35 | case "adverb":
36 | commentParts = append(commentParts, adverb(f))
37 | case "interjection":
38 | commentParts = append(commentParts, interjection(f))
39 | case "preposition":
40 | commentParts = append(commentParts, preposition(f))
41 | case "determiner":
42 | commentParts = append(commentParts, nounDeterminer(f))
43 | default:
44 | // Should never hit
45 | panic("Invalid word type")
46 | }
47 | }
48 |
49 | // Combine the words into a sentence
50 | sentence := strings.Join(commentParts, " ")
51 |
52 | // Capitalize the first letter
53 | sentence = title(sentence)
54 |
55 | // Add a period to the end of the sentence
56 | sentence = sentence + "."
57 |
58 | return sentence
59 | }
60 |
61 | func addWordCommentLookup() {
62 | AddFuncLookup("comment", Info{
63 | Display: "Comment",
64 | Category: "word",
65 | Description: "Statement or remark expressing an opinion, observation, or reaction",
66 | Example: "wow",
67 | Output: "string",
68 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
69 | return interjection(f), nil
70 | },
71 | })
72 | }
73 |
--------------------------------------------------------------------------------
/word_comment_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleComment() {
9 | Seed(11)
10 | fmt.Println(Comment())
11 |
12 | // Output: Fear Drink To Heart.
13 | }
14 |
15 | func ExampleFaker_Comment() {
16 | f := New(11)
17 | fmt.Println(f.Comment())
18 |
19 | // Output: Fear Drink To Heart.
20 | }
21 |
22 | func TestComment(t *testing.T) {
23 | f := New(11)
24 | for i := 0; i < 1000; i++ {
25 | f.Comment()
26 | }
27 | }
28 |
29 | func BenchmarkComment(b *testing.B) {
30 | for i := 0; i < b.N; i++ {
31 | Comment()
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/word_connective_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleConnective() {
9 | Seed(11)
10 | fmt.Println(Connective())
11 |
12 | // Output: through
13 | }
14 |
15 | func ExampleFaker_Connective() {
16 | f := New(11)
17 | fmt.Println(f.Connective())
18 |
19 | // Output: through
20 | }
21 |
22 | func BenchmarkConnective(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Connective()
25 | }
26 | }
27 |
28 | func ExampleConnectiveTime() {
29 | Seed(11)
30 | fmt.Println(ConnectiveTime())
31 |
32 | // Output: when
33 | }
34 |
35 | func ExampleFaker_ConnectiveTime() {
36 | f := New(11)
37 | fmt.Println(f.ConnectiveTime())
38 |
39 | // Output: when
40 | }
41 |
42 | func BenchmarkConnectiveTime(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | ConnectiveTime()
45 | }
46 | }
47 |
48 | func ExampleConnectiveComparative() {
49 | Seed(11)
50 | fmt.Println(ConnectiveComparative())
51 |
52 | // Output: after all
53 | }
54 |
55 | func ExampleFaker_ConnectiveComparative() {
56 | f := New(11)
57 | fmt.Println(f.ConnectiveComparative())
58 |
59 | // Output: after all
60 | }
61 |
62 | func BenchmarkConnectiveComparative(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | ConnectiveComparative()
65 | }
66 | }
67 |
68 | func ExampleConnectiveComplaint() {
69 | Seed(11)
70 | fmt.Println(ConnectiveComplaint())
71 |
72 | // Output: i.e.
73 | }
74 |
75 | func ExampleFaker_ConnectiveComplaint() {
76 | f := New(11)
77 | fmt.Println(f.ConnectiveComplaint())
78 |
79 | // Output: i.e.
80 | }
81 |
82 | func BenchmarkConnectiveComplaint(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | ConnectiveComplaint()
85 | }
86 | }
87 |
88 | func ExampleConnectiveListing() {
89 | Seed(11)
90 | fmt.Println(ConnectiveListing())
91 |
92 | // Output: in summation
93 | }
94 |
95 | func ExampleFaker_ConnectiveListing() {
96 | f := New(11)
97 | fmt.Println(f.ConnectiveListing())
98 |
99 | // Output: in summation
100 | }
101 |
102 | func BenchmarkConnectiveListing(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | ConnectiveListing()
105 | }
106 | }
107 |
108 | func ExampleConnectiveCasual() {
109 | Seed(11)
110 | fmt.Println(ConnectiveCasual())
111 |
112 | // Output: though
113 | }
114 |
115 | func ExampleFaker_ConnectiveCasual() {
116 | f := New(11)
117 | fmt.Println(f.ConnectiveCasual())
118 |
119 | // Output: though
120 | }
121 |
122 | func BenchmarkConnectiveCasual(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | ConnectiveCasual()
125 | }
126 | }
127 |
128 | func ExampleConnectiveExamplify() {
129 | Seed(11)
130 | fmt.Println(ConnectiveExamplify())
131 |
132 | // Output: unless
133 | }
134 |
135 | func ExampleFaker_ConnectiveExamplify() {
136 | f := New(11)
137 | fmt.Println(f.ConnectiveExamplify())
138 |
139 | // Output: unless
140 | }
141 |
142 | func BenchmarkConnectiveExamplify(b *testing.B) {
143 | for i := 0; i < b.N; i++ {
144 | ConnectiveExamplify()
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/word_general.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "strings"
5 |
6 | "github.com/brianvoe/gofakeit/v7/data"
7 | )
8 |
9 | // Word will generate a random word
10 | func Word() string { return word(GlobalFaker) }
11 |
12 | // Word will generate a random word
13 | func (f *Faker) Word() string { return word(f) }
14 |
15 | func word(f *Faker) string {
16 | word := getRandValue(f, []string{"word", randomString(f, data.WordKeys)})
17 |
18 | // Word may return a couple of words, if so we will split on space and return a random word
19 | if strings.Contains(word, " ") {
20 | return randomString(f, strings.Split(word, " "))
21 | }
22 |
23 | return word
24 | }
25 |
26 | func addWordGeneralLookup() {
27 | AddFuncLookup("word", Info{
28 | Display: "Word",
29 | Category: "word",
30 | Description: "Basic unit of language representing a concept or thing, consisting of letters and having meaning",
31 | Example: "man",
32 | Output: "string",
33 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
34 | return word(f), nil
35 | },
36 | })
37 | }
38 |
--------------------------------------------------------------------------------
/word_general_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleWord() {
9 | Seed(11)
10 | fmt.Println(Word())
11 |
12 | // Output: bathe
13 | }
14 |
15 | func ExampleFaker_Word() {
16 | f := New(11)
17 | fmt.Println(f.Word())
18 |
19 | // Output: bathe
20 | }
21 |
22 | func BenchmarkWord(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Word()
25 | }
26 | }
27 |
28 | func TestWord(t *testing.T) {
29 | for i := 0; i < 10000; i++ {
30 | if Word() == "" {
31 | t.Errorf("result should not be blank")
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/word_grammar.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "unicode"
5 | )
6 |
7 | // SentenceSimple will generate a random simple sentence
8 | func SentenceSimple() string { return sentenceSimple(GlobalFaker) }
9 |
10 | // SentenceSimple will generate a random simple sentence
11 | func (f *Faker) SentenceSimple() string { return sentenceSimple(f) }
12 |
13 | func sentenceSimple(f *Faker) string {
14 | // simple sentence consists of a noun phrase and a verb phrase
15 | str := phraseNoun(f) + " " + phraseVerb(f) + "."
16 |
17 | // capitalize the first letter
18 | strR := []rune(str)
19 | strR[0] = unicode.ToUpper(strR[0])
20 | return string(strR)
21 | }
22 |
23 | func addWordGrammerLookup() {
24 | AddFuncLookup("sentencesimple", Info{
25 | Display: "Simple Sentence",
26 | Category: "word",
27 | Description: "Group of words that expresses a complete thought",
28 | Example: "A tribe fly the lemony kitchen.",
29 | Output: "string",
30 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
31 | return sentenceSimple(f), nil
32 | },
33 | })
34 | }
35 |
--------------------------------------------------------------------------------
/word_grammar_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleSentenceSimple() {
9 | Seed(11)
10 | fmt.Println(SentenceSimple())
11 |
12 | // Output: A fear selfishly cook a tough doctor hardly innocently to realistic project utterly ingeniously.
13 | }
14 |
15 | func ExampleFaker_SentenceSimple() {
16 | f := New(11)
17 | fmt.Println(f.SentenceSimple())
18 |
19 | // Output: A fear selfishly cook a tough doctor hardly innocently to realistic project utterly ingeniously.
20 | }
21 |
22 | func BenchmarkSentenceSimple(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | SentenceSimple()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/word_helper.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "strings"
5 | )
6 |
7 | // This will look at a few things to determine what kind of article to use for the word
8 | func getArticle(word string) string {
9 | // If nothing is passed return empty
10 | if word == "" {
11 | return ""
12 | }
13 |
14 | word = strings.ToLower(word)
15 | letters := strings.Split(word, "")
16 | firstLetter := ""
17 | secondLetter := ""
18 | if len(letters) > 0 {
19 | firstLetter = letters[0]
20 | }
21 | if len(letters) > 1 {
22 | secondLetter = letters[1]
23 | }
24 |
25 | // If the word starts with a, e, i, o, use an article
26 | if firstLetter == "a" || firstLetter == "e" || firstLetter == "i" || firstLetter == "o" {
27 | return "an"
28 | }
29 |
30 | // If the word starts with a u and n or l, use an article
31 | if firstLetter == "u" {
32 | if secondLetter == "n" || secondLetter == "l" {
33 | return "an"
34 | }
35 | }
36 |
37 | // If the word starts with a vowel, use an article
38 | if firstLetter == "h" {
39 | if secondLetter == "i" {
40 | return "an"
41 | }
42 | }
43 |
44 | return "a"
45 | }
46 |
--------------------------------------------------------------------------------
/word_helper_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import "testing"
4 |
5 | func TestGetArticle(t *testing.T) {
6 | // If nothing is passed return empty
7 | if getArticle("") != "" {
8 | t.Error("Expected empty string, got: ", getArticle(""))
9 | }
10 |
11 | // If the word starts with a, e, i, o, use an article
12 | if getArticle("apple") != "an" {
13 | t.Error("Expected an, got: ", getArticle("apple"))
14 | }
15 |
16 | if getArticle("elephant") != "an" {
17 | t.Error("Expected an, got: ", getArticle("elephant"))
18 | }
19 |
20 | if getArticle("independent") != "an" {
21 | t.Error("Expected an, got: ", getArticle("independent"))
22 | }
23 |
24 | if getArticle("open") != "an" {
25 | t.Error("Expected an, got: ", getArticle("open"))
26 | }
27 |
28 | // If the word starts with a u and n or l, use an article
29 | if getArticle("underwear") != "an" {
30 | t.Error("Expected an, got: ", getArticle("underwear"))
31 | }
32 |
33 | if getArticle("ulcer") != "an" {
34 | t.Error("Expected an, got: ", getArticle("ulcer"))
35 | }
36 |
37 | // If the word starts with a vowel, use an article
38 | if getArticle("hippos") != "an" {
39 | t.Error("Expected an, got: ", getArticle("hippose"))
40 | }
41 |
42 | // Pass a word that will return "a"
43 | if getArticle("bus") != "a" {
44 | t.Error("Expected a, got: ", getArticle("bus"))
45 | }
46 |
47 | if getArticle("plane") != "a" {
48 | t.Error("Expected a, got: ", getArticle("plane"))
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/word_misc.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | // Interjection will generate a random word expressing emotion
4 | func Interjection() string { return interjection(GlobalFaker) }
5 |
6 | // Interjection will generate a random word expressing emotion
7 | func (f *Faker) Interjection() string { return interjection(f) }
8 |
9 | func interjection(f *Faker) string { return getRandValue(f, []string{"word", "interjection"}) }
10 |
11 | func addWordMiscLookup() {
12 | AddFuncLookup("interjection", Info{
13 | Display: "Interjection",
14 | Category: "word",
15 | Description: "Word expressing emotion",
16 | Example: "wow",
17 | Output: "string",
18 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
19 | return interjection(f), nil
20 | },
21 | })
22 | }
23 |
--------------------------------------------------------------------------------
/word_misc_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleInterjection() {
9 | Seed(11)
10 | fmt.Println(Interjection())
11 |
12 | // Output: alas
13 | }
14 |
15 | func ExampleFaker_Interjection() {
16 | f := New(11)
17 | fmt.Println(f.Interjection())
18 |
19 | // Output: alas
20 | }
21 |
22 | func BenchmarkInterjection(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Interjection()
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/word_phrase_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExamplePhrase() {
9 | Seed(11)
10 | fmt.Println(Phrase())
11 |
12 | // Output: how many siblings do you have
13 | }
14 |
15 | func ExampleFaker_Phrase() {
16 | f := New(11)
17 | fmt.Println(f.Phrase())
18 |
19 | // Output: how many siblings do you have
20 | }
21 |
22 | func BenchmarkPhrase(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Phrase()
25 | }
26 | }
27 |
28 | func ExamplePhraseNoun() {
29 | Seed(11)
30 | fmt.Println(PhraseNoun())
31 |
32 | // Output: a fear
33 | }
34 |
35 | func ExampleFaker_PhraseNoun() {
36 | f := New(11)
37 | fmt.Println(f.PhraseNoun())
38 |
39 | // Output: a fear
40 | }
41 |
42 | func BenchmarkPhraseNoun(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | PhraseNoun()
45 | }
46 | }
47 |
48 | func ExamplePhraseVerb() {
49 | Seed(11)
50 | fmt.Println(PhraseVerb())
51 |
52 | // Output: bathe the jittery trip totally brightly under a troubling part scarcely unexpectedly
53 | }
54 |
55 | func ExampleFaker_PhraseVerb() {
56 | f := New(11)
57 | fmt.Println(f.PhraseVerb())
58 |
59 | // Output: bathe the jittery trip totally brightly under a troubling part scarcely unexpectedly
60 | }
61 |
62 | func BenchmarkPhraseVerb(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | PhraseVerb()
65 | }
66 | }
67 |
68 | func ExamplePhraseAdverb() {
69 | Seed(11)
70 | fmt.Println(PhraseAdverb())
71 |
72 | // Output: successfully
73 | }
74 |
75 | func ExampleFaker_PhraseAdverb() {
76 | f := New(11)
77 | fmt.Println(f.PhraseAdverb())
78 |
79 | // Output: successfully
80 | }
81 |
82 | func BenchmarkPhraseAdverb(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | PhraseAdverb()
85 | }
86 | }
87 |
88 | func ExamplePhrasePreposition() {
89 | Seed(11)
90 | fmt.Println(PhrasePreposition())
91 |
92 | // Output: with an archipelago
93 | }
94 |
95 | func ExampleFaker_PhrasePreposition() {
96 | f := New(11)
97 | fmt.Println(f.PhrasePreposition())
98 |
99 | // Output: with an archipelago
100 | }
101 |
102 | func BenchmarkPhrasePreposition(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | PhrasePreposition()
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/word_preposition.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | // Preposition will generate a random preposition
4 | func Preposition() string { return preposition(GlobalFaker) }
5 |
6 | // Preposition will generate a random preposition
7 | func (f *Faker) Preposition() string { return preposition(f) }
8 |
9 | func preposition(f *Faker) string {
10 | var prepType = map[int]string{
11 | 0: "preposition_simple",
12 | 1: "preposition_double",
13 | 2: "preposition_compound",
14 | }
15 | return getRandValue(f, []string{"word", prepType[number(f, 0, 2)]})
16 | }
17 |
18 | // PrepositionSimple will generate a random simple preposition
19 | func PrepositionSimple() string { return prepositionSimple(GlobalFaker) }
20 |
21 | // PrepositionSimple will generate a random simple preposition
22 | func (f *Faker) PrepositionSimple() string { return prepositionSimple(f) }
23 |
24 | func prepositionSimple(f *Faker) string {
25 | return getRandValue(f, []string{"word", "preposition_simple"})
26 | }
27 |
28 | // PrepositionDouble will generate a random double preposition
29 | func PrepositionDouble() string { return prepositionDouble(GlobalFaker) }
30 |
31 | // PrepositionDouble will generate a random double preposition
32 | func (f *Faker) PrepositionDouble() string { return prepositionDouble(f) }
33 |
34 | func prepositionDouble(f *Faker) string {
35 | return getRandValue(f, []string{"word", "preposition_double"})
36 | }
37 |
38 | // PrepositionCompound will generate a random compound preposition
39 | func PrepositionCompound() string { return prepositionCompound(GlobalFaker) }
40 |
41 | // PrepositionCompound will generate a random compound preposition
42 | func (f *Faker) PrepositionCompound() string { return prepositionCompound(f) }
43 |
44 | func prepositionCompound(f *Faker) string {
45 | return getRandValue(f, []string{"word", "preposition_compound"})
46 | }
47 |
48 | func addWordPrepositionLookup() {
49 | AddFuncLookup("preposition", Info{
50 | Display: "Preposition",
51 | Category: "word",
52 | Description: "Words used to express the relationship of a noun or pronoun to other words in a sentence",
53 | Example: "other than",
54 | Output: "string",
55 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
56 | return preposition(f), nil
57 | },
58 | })
59 |
60 | AddFuncLookup("prepositionsimple", Info{
61 | Display: "Preposition Simple",
62 | Category: "word",
63 | Description: "Single-word preposition showing relationships between 2 parts of a sentence",
64 | Example: "out",
65 | Output: "string",
66 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
67 | return prepositionSimple(f), nil
68 | },
69 | })
70 |
71 | AddFuncLookup("prepositiondouble", Info{
72 | Display: "Preposition Double",
73 | Category: "word",
74 | Description: "Two-word combination preposition, indicating a complex relation",
75 | Example: "before",
76 | Output: "string",
77 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
78 | return prepositionDouble(f), nil
79 | },
80 | })
81 |
82 | AddFuncLookup("prepositioncompound", Info{
83 | Display: "Preposition Compound",
84 | Category: "word",
85 | Description: "Preposition that can be formed by combining two or more prepositions",
86 | Example: "according to",
87 | Output: "string",
88 | Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
89 | return prepositionCompound(f), nil
90 | },
91 | })
92 | }
93 |
--------------------------------------------------------------------------------
/word_preposition_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExamplePreposition() {
9 | Seed(11)
10 | fmt.Println(Preposition())
11 |
12 | // Output: instead of
13 | }
14 |
15 | func ExampleFaker_Preposition() {
16 | f := New(11)
17 | fmt.Println(f.Preposition())
18 |
19 | // Output: instead of
20 | }
21 |
22 | func BenchmarkPreposition(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Preposition()
25 | }
26 | }
27 |
28 | func ExamplePrepositionSimple() {
29 | Seed(11)
30 | fmt.Println(PrepositionSimple())
31 |
32 | // Output: with
33 | }
34 |
35 | func ExampleFaker_PrepositionSimple() {
36 | f := New(11)
37 | fmt.Println(f.PrepositionSimple())
38 |
39 | // Output: with
40 | }
41 |
42 | func BenchmarkPrepositionSimple(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | PrepositionSimple()
45 | }
46 | }
47 |
48 | func ExamplePrepositionDouble() {
49 | Seed(11)
50 | fmt.Println(PrepositionDouble())
51 |
52 | // Output: next to
53 | }
54 |
55 | func ExampleFaker_PrepositionDouble() {
56 | f := New(11)
57 | fmt.Println(f.PrepositionDouble())
58 |
59 | // Output: next to
60 | }
61 |
62 | func BenchmarkPrepositionDouble(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | PrepositionDouble()
65 | }
66 | }
67 |
68 | func ExamplePrepositionCompound() {
69 | Seed(11)
70 | fmt.Println(PrepositionCompound())
71 |
72 | // Output: other than
73 | }
74 |
75 | func ExampleFaker_PrepositionCompound() {
76 | f := New(11)
77 | fmt.Println(f.PrepositionCompound())
78 |
79 | // Output: other than
80 | }
81 |
82 | func BenchmarkPrepositionCompound(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | PrepositionCompound()
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/word_pronoun_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExamplePronoun() {
9 | Seed(11)
10 | fmt.Println(Pronoun())
11 |
12 | // Output: some
13 | }
14 |
15 | func ExampleFaker_Pronoun() {
16 | f := New(11)
17 | fmt.Println(f.Pronoun())
18 |
19 | // Output: some
20 | }
21 |
22 | func BenchmarkPronoun(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Pronoun()
25 | }
26 | }
27 |
28 | func ExamplePronounPersonal() {
29 | Seed(11)
30 | fmt.Println(PronounPersonal())
31 |
32 | // Output: they
33 | }
34 |
35 | func ExampleFaker_PronounPersonal() {
36 | f := New(11)
37 | fmt.Println(f.PronounPersonal())
38 |
39 | // Output: they
40 | }
41 |
42 | func BenchmarkPronounPersonal(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | PronounPersonal()
45 | }
46 | }
47 |
48 | func ExamplePronounObject() {
49 | Seed(11)
50 | fmt.Println(PronounObject())
51 |
52 | // Output: them
53 | }
54 |
55 | func ExampleFaker_PronounObject() {
56 | f := New(11)
57 | fmt.Println(f.PronounObject())
58 |
59 | // Output: them
60 | }
61 |
62 | func BenchmarkPronounObject(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | PronounObject()
65 | }
66 | }
67 |
68 | func ExamplePronounPossessive() {
69 | Seed(11)
70 | fmt.Println(PronounPossessive())
71 |
72 | // Output: theirs
73 | }
74 |
75 | func ExampleFaker_PronounPossessive() {
76 | f := New(11)
77 | fmt.Println(f.PronounPossessive())
78 |
79 | // Output: theirs
80 | }
81 |
82 | func BenchmarkPronounPossessive(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | PronounPossessive()
85 | }
86 | }
87 |
88 | func ExamplePronounReflective() {
89 | Seed(11)
90 | fmt.Println(PronounReflective())
91 |
92 | // Output: itself
93 | }
94 |
95 | func ExampleFaker_PronounReflective() {
96 | f := New(11)
97 | fmt.Println(f.PronounReflective())
98 |
99 | // Output: itself
100 | }
101 |
102 | func BenchmarkPronounReflective(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | PronounReflective()
105 | }
106 | }
107 |
108 | func ExamplePronounIndefinite() {
109 | Seed(11)
110 | fmt.Println(PronounIndefinite())
111 |
112 | // Output: somebody
113 | }
114 |
115 | func ExampleFaker_PronounIndefinite() {
116 | f := New(11)
117 | fmt.Println(f.PronounIndefinite())
118 |
119 | // Output: somebody
120 | }
121 |
122 | func BenchmarkPronounIndefinite(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | PronounIndefinite()
125 | }
126 | }
127 |
128 | func ExamplePronounDemonstrative() {
129 | Seed(11)
130 | fmt.Println(PronounDemonstrative())
131 |
132 | // Output: this
133 | }
134 |
135 | func ExampleFaker_PronounDemonstrative() {
136 | f := New(11)
137 | fmt.Println(f.PronounDemonstrative())
138 |
139 | // Output: this
140 | }
141 |
142 | func BenchmarkPronounDemonstrative(b *testing.B) {
143 | for i := 0; i < b.N; i++ {
144 | PronounDemonstrative()
145 | }
146 | }
147 |
148 | func ExamplePronounInterrogative() {
149 | Seed(11)
150 | fmt.Println(PronounInterrogative())
151 |
152 | // Output: how
153 | }
154 |
155 | func ExampleFaker_PronounInterrogative() {
156 | f := New(11)
157 | fmt.Println(f.PronounInterrogative())
158 |
159 | // Output: how
160 | }
161 |
162 | func BenchmarkPronounInterrogative(b *testing.B) {
163 | for i := 0; i < b.N; i++ {
164 | PronounInterrogative()
165 | }
166 | }
167 |
168 | func ExamplePronounRelative() {
169 | Seed(11)
170 | fmt.Println(PronounRelative())
171 |
172 | // Output: whomever
173 | }
174 |
175 | func ExampleFaker_PronounRelative() {
176 | f := New(11)
177 | fmt.Println(f.PronounRelative())
178 |
179 | // Output: whomever
180 | }
181 |
182 | func BenchmarkPronounRelative(b *testing.B) {
183 | for i := 0; i < b.N; i++ {
184 | PronounRelative()
185 | }
186 | }
187 |
--------------------------------------------------------------------------------
/word_verb_test.go:
--------------------------------------------------------------------------------
1 | package gofakeit
2 |
3 | import (
4 | "fmt"
5 | "testing"
6 | )
7 |
8 | func ExampleVerb() {
9 | Seed(11)
10 | fmt.Println(Verb())
11 |
12 | // Output: would
13 | }
14 |
15 | func ExampleFaker_Verb() {
16 | f := New(11)
17 | fmt.Println(f.Verb())
18 |
19 | // Output: would
20 | }
21 |
22 | func BenchmarkVerb(b *testing.B) {
23 | for i := 0; i < b.N; i++ {
24 | Verb()
25 | }
26 | }
27 |
28 | func ExampleVerbAction() {
29 | Seed(11)
30 | fmt.Println(VerbAction())
31 |
32 | // Output: paint
33 | }
34 |
35 | func ExampleFaker_VerbAction() {
36 | f := New(11)
37 | fmt.Println(f.VerbAction())
38 |
39 | // Output: paint
40 | }
41 |
42 | func BenchmarkVerbAction(b *testing.B) {
43 | for i := 0; i < b.N; i++ {
44 | VerbAction()
45 | }
46 | }
47 |
48 | func ExampleVerbTransitive() {
49 | Seed(11)
50 | fmt.Println(VerbTransitive())
51 |
52 | // Output: upgrade
53 | }
54 |
55 | func ExampleFaker_VerbTransitive() {
56 | f := New(11)
57 | fmt.Println(f.VerbTransitive())
58 |
59 | // Output: upgrade
60 | }
61 |
62 | func BenchmarkVerbTransitive(b *testing.B) {
63 | for i := 0; i < b.N; i++ {
64 | VerbTransitive()
65 | }
66 | }
67 |
68 | func ExampleVerbIntransitive() {
69 | Seed(11)
70 | fmt.Println(VerbIntransitive())
71 |
72 | // Output: vomit
73 | }
74 |
75 | func ExampleFaker_VerbIntransitive() {
76 | f := New(11)
77 | fmt.Println(f.VerbIntransitive())
78 |
79 | // Output: vomit
80 | }
81 |
82 | func BenchmarkVerbIntransitive(b *testing.B) {
83 | for i := 0; i < b.N; i++ {
84 | VerbIntransitive()
85 | }
86 | }
87 |
88 | func ExampleVerbLinking() {
89 | Seed(11)
90 | fmt.Println(VerbLinking())
91 |
92 | // Output: must
93 | }
94 |
95 | func ExampleFaker_VerbLinking() {
96 | f := New(11)
97 | fmt.Println(f.VerbLinking())
98 |
99 | // Output: must
100 | }
101 |
102 | func BenchmarkVerbLinking(b *testing.B) {
103 | for i := 0; i < b.N; i++ {
104 | VerbLinking()
105 | }
106 | }
107 |
108 | func ExampleVerbHelping() {
109 | Seed(11)
110 | fmt.Println(VerbHelping())
111 |
112 | // Output: am
113 | }
114 |
115 | func ExampleFaker_VerbHelping() {
116 | f := New(11)
117 | fmt.Println(f.VerbHelping())
118 |
119 | // Output: am
120 | }
121 |
122 | func BenchmarkVerbHelping(b *testing.B) {
123 | for i := 0; i < b.N; i++ {
124 | VerbHelping()
125 | }
126 | }
127 |
--------------------------------------------------------------------------------