/ Data Structures

Random fake data generator written in go

Random fake data generator written in go

gofakeit

Random data generator written in go.

Features

  • Every function has an example and a benchmark,
    see benchmarks
  • Zero dependencies
  • Randomizes user defined structs
  • Numerous functions for regular use

120+ Functions!!!

If there is something that is generic enough missing from this package add an issue and let me know what you need.
Most of the time i'll add it!

Seed

If you would like to ensure randomization on initial use be sure to seed it first

gofakeit.Seed(time.Now().UnixNano()) // or gofakeit.Seed(0)

Installation

go get github.com/brianvoe/gofakeit/v4

Example

import "github.com/brianvoe/gofakeit/v4"

gofakeit.Seed(0)

gofakeit.Name() // Markus Moen
gofakeit.Email() // [email protected]
gofakeit.Phone() // (570)245-7485
gofakeit.BS() // front-end
gofakeit.BeerName() // Duvel
gofakeit.Color() // MediumOrchid
gofakeit.Company() // Moen, Pagac and Wuckert
gofakeit.CreditCardNumber() // 4287271570245748
gofakeit.HackerPhrase() // Connecting the array won't do anything, we need to generate the haptic COM driver!
gofakeit.JobTitle() // Director
gofakeit.Password(true, true, true, true, true, 32) // WV10MzLxq2DX79w1omH97_0ga59j8!kj
gofakeit.CurrencyShort() // USD
// See full list below

Example Struct

import "github.com/brianvoe/gofakeit/v4"

// Create structs with random injected data
type Foo struct {
	Bar     string
	Int     int
	Pointer *int
	Name    string  `fake:"{person.first}"`
	Skip    *string `fake:"skip"` // Set to "skip" to not generate data for
}

// Pass your struct as a pointer
var f Foo
gofakeit.Struct(&f)

fmt.Printf("f.Bar:%s\n", f.Bar) // f.Bar:hrukpttuezptneuvunh
fmt.Printf("f.Int:%d\n", f.Int) // f.Int:-7825289004089916589
fmt.Printf("f.Pointer:%d\n", *f.Pointer) // f.Pointer:-343806609094473732
fmt.Printf("f.Name:%v\n", f.Name) // f.Skip:fred
fmt.Printf("f.Skip:%v\n", f.Skip) // f.Skip:<nil>

Person

Person() *PersonInfo
Name() string
NamePrefix() string
NameSuffix() string
FirstName() string
LastName() string
Gender() string
SSN() string
Contact() *ContactInfo
Email() string
Phone() string
PhoneFormatted() string
Username() string
Password(lower bool, upper bool, numeric bool, special bool, space bool, num int) string

Address

Address() *AddressInfo
City() string
Country() string
CountryAbr() string
State() string
StateAbr() string
StatusCode() string
Street() string
StreetName() string
StreetNumber() string
StreetPrefix() string
StreetSuffix() string
Zip() string
Latitude() float64
LatitudeInRange() (float64, error)
Longitude() float64
LongitudeInRange() (float64, error)

Beer

BeerAlcohol() string
BeerBlg() string
BeerHop() string
BeerIbu() string
BeerMalt() string
BeerName() string
BeerStyle() string
BeerYeast() string

Cars

Vehicle() *VehicleInfo
CarMaker() string
CarModel() string
VehicleType() string
FuelType() string
TransmissionGearType() string

Words

Word() string
Sentence(wordCount int) string
Paragraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string
Question() string
Quote() string

Misc

Struct(v interface{})
Map() map[string]interface{}
Generate() string
Bool() bool
UUID() string

Colors

Color() string
HexColor() string
RGBColor() string
SafeColor() string

Internet

URL() string
ImageURL(width int, height int) string
DomainName() string
DomainSuffix() string
IPv4Address() string
IPv6Address() string
SimpleStatusCode() int
LogLevel(logType string) string
HTTPMethod() string
UserAgent() string
ChromeUserAgent() string
FirefoxUserAgent() string
OperaUserAgent() string
SafariUserAgent() string

Date/Time

Date() time.Time
DateRange(start, end time.Time) time.Time
NanoSecond() int
Second() int
Minute() int
Hour() int
Month() string
Day() int
WeekDay() string
Year() int
TimeZone() string
TimeZoneAbv() string
TimeZoneFull() string
TimeZoneOffset() float32

Payment

Price(min, max float64) float64
CreditCard() *CreditCardInfo
CreditCardCvv() string
CreditCardExp() string
CreditCardNumber() int
CreditCardNumberLuhn() int
CreditCardType() string
Currency() *CurrencyInfo
CurrencyLong() string
CurrencyShort() string

Company

BS() string
BuzzWord() string
Company() string
CompanySuffix() string
Job() *JobInfo
JobDescriptor() string
JobLevel() string
JobTitle() string

Hacker

HackerAbbreviation() string
HackerAdjective() string
HackerIngverb() string
HackerNoun() string
HackerPhrase() string
HackerVerb() string

Hipster

HipsterWord() string
HipsterSentence(wordCount int) string
HipsterParagraph(paragraphCount int, sentenceCount int, wordCount int, separator string) string

Animal

PetName() string

Languages

Language() string
LanguageAbbreviation() string
ProgrammingLanguage() string

File

Extension() string
MimeType() string

Numbers

Number(min int, max int) int
Numerify(str string) string
Int8() int8
Int16() int16
Int32() int32
Int64() int64
Uint8() uint8
Uint16() uint16
Uint32() uint32
Uint64() uint64
Float32() float32
Float32Range(min, max float32) float32
Float64() float64
Float64Range(min, max float64) float64
ShuffleInts(a []int)

String

Digit() string
Letter() string
Lexify(str string) string
RandString(a []string) string
ShuffleStrings(a []string)

GitHub

Comments