Skip to content

Commit a4c5665

Browse files
committed
Merge branch 'develop'
2 parents a5e6a89 + a980781 commit a4c5665

File tree

144 files changed

+5190
-8802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+5190
-8802
lines changed

BENCHMARKS.md

Lines changed: 326 additions & 455 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![alt text](https://raw.githubusercontent.com/brianvoe/gofakeit/master/logo.png)
22

3-
# Gofakeit [![Go Report Card](https://goreportcard.com/badge/github.com/brianvoe/gofakeit)](https://goreportcard.com/report/github.com/brianvoe/gofakeit) ![Test](https://github.com/brianvoe/gofakeit/workflows/Test/badge.svg?branch=master) [![GoDoc](https://godoc.org/github.com/brianvoe/gofakeit/v6?status.svg)](https://godoc.org/github.com/brianvoe/gofakeit/v6) [![license](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/brianvoe/gofakeit/master/LICENSE.txt)
3+
# Gofakeit [![Go Report Card](https://goreportcard.com/badge/github.com/brianvoe/gofakeit)](https://goreportcard.com/report/github.com/brianvoe/gofakeit) ![Test](https://github.com/brianvoe/gofakeit/workflows/Test/badge.svg?branch=master) [![GoDoc](https://godoc.org/github.com/brianvoe/gofakeit/v7?status.svg)](https://godoc.org/github.com/brianvoe/gofakeit/v7) [![license](http://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/brianvoe/gofakeit/master/LICENSE.txt)
44

55
Random data generator written in go
66

@@ -33,13 +33,13 @@ Thank you to all our Gofakeit contributors!
3333
## Installation
3434

3535
```go
36-
go get github.com/brianvoe/gofakeit/v6
36+
go get github.com/brianvoe/gofakeit/v7
3737
```
3838

3939
## Simple Usage
4040

4141
```go
42-
import "github.com/brianvoe/gofakeit/v6"
42+
import "github.com/brianvoe/gofakeit/v7"
4343

4444
gofakeit.Name() // Markus Moen
4545
gofakeit.Email() // alaynawuckert@kozey.biz
@@ -65,7 +65,7 @@ If you need a reproducible outcome you can set it via the Seed function call. Ev
6565
this repo sets it for testing purposes.
6666

6767
```go
68-
import "github.com/brianvoe/gofakeit/v6"
68+
import "github.com/brianvoe/gofakeit/v7"
6969

7070
gofakeit.Seed(0) // If 0 will use crypto/rand to generate a number
7171

@@ -76,25 +76,43 @@ gofakeit.Seed(8675309) // Set it to whatever number you want
7676

7777
## Random Sources
7878

79-
Gofakeit has a few rand sources, by default it uses math.Rand and uses mutex locking to allow for safe goroutines.
79+
Gofakeit has a few rand sources, by default it uses math/rand/v2 PCG which is a pseudo random number generator and is thread locked.
8080

81-
If you want to use a more performant source please use NewUnlocked. Be aware that it is not goroutine safe.
81+
If you want to see other potential sources you can see the sub package [Source](https://pkg.go.dev/github.com/brianvoe/gofakeit/v7/source) for more information.
8282

8383
```go
84-
import "github.com/brianvoe/gofakeit/v6"
84+
import (
85+
"github.com/brianvoe/gofakeit/v7"
86+
"github.com/brianvoe/gofakeit/v7/source"
87+
"math/rand/v2"
88+
)
8589

86-
// Uses math/rand(Pseudo) with mutex locking
90+
// Uses math/rand/v2(PCG Pseudo) with mutex locking
8791
faker := gofakeit.New(0)
8892

89-
// Uses math/rand(Pseudo) with NO mutext locking
90-
// More performant but not goroutine safe.
91-
faker := gofakeit.NewUnlocked(0)
93+
// NewFaker takes in a source and whether or not it should be thread safe
94+
faker := gofakeit.NewFaker(source rand.Source, threadSafe bool)
9295

93-
// Uses crypto/rand(cryptographically secure) with mutext locking
94-
faker := gofakeit.NewCrypto()
96+
// PCG Pseudo
97+
faker := gofakeit.NewFaker(rand.NewPCG(11, 11), true)
9598

96-
// Pass in your own random source
97-
faker := gofakeit.NewCustom()
99+
// ChaCha8
100+
faker := gofakeit.NewFaker(rand.NewChaCha8([32]byte{0, 1, 2, 3, 4, 5}), true)
101+
102+
103+
// Additional from Gofakeit sub package source
104+
105+
// JSF(Jenkins Small Fast)
106+
faker := gofakeit.NewFaker(source.NewJSF(11), true)
107+
108+
// SFC(Simple Fast Counter)
109+
faker := gofakeit.NewFaker(source.NewSFC(11), true)
110+
111+
// Crypto - Uses crypto/rand
112+
faker := gofakeit.NewFaker(source.NewCrypto(), true)
113+
114+
// Dumb - simple incrementing number
115+
faker := gofakeit.NewFaker(source.NewDumb(11), true)
98116
```
99117

100118
## Global Rand Set
@@ -103,10 +121,13 @@ If you would like to use the simple function calls but need to use something lik
103121
crypto/rand you can override the default global with the random source that you want.
104122

105123
```go
106-
import "github.com/brianvoe/gofakeit/v6"
124+
import (
125+
"github.com/brianvoe/gofakeit/v7"
126+
"math/rand/v2"
127+
)
107128

108-
faker := gofakeit.NewCrypto()
109-
gofakeit.SetGlobalFaker(faker)
129+
faker := gofakeit.New(0)
130+
gofakeit.GlobalFaker = faker
110131
```
111132

112133
## Struct
@@ -117,7 +138,7 @@ as well as some non-basic like time.Time.
117138
Struct fields can also use tags to more specifically generate data for that field type.
118139

119140
```go
120-
import "github.com/brianvoe/gofakeit/v6"
141+
import "github.com/brianvoe/gofakeit/v7"
121142

122143
// Create structs with random injected data
123144
type Foo struct {
@@ -147,14 +168,14 @@ type Bar struct {
147168

148169
// Pass your struct as a pointer
149170
var f Foo
150-
gofakeit.Struct(&f)
171+
err := gofakeit.Struct(&f)
151172

152173
fmt.Println(f.Str) // hrukpttuezptneuvunh
153174
fmt.Println(f.Int) // -7825289004089916589
154175
fmt.Println(*f.Pointer) // -343806609094473732
155176
fmt.Println(f.Name) // fred
156177
fmt.Println(f.Sentence) // Record river mind.
157-
fmt.Println(f.RandStr) // world
178+
fmt.Println(fStr) // world
158179
fmt.Println(f.Number) // 4
159180
fmt.Println(f.Regex) // cbdfc
160181
fmt.Println(f.Map) // map[PxLIo:52 lxwnqhqc:846]
@@ -229,8 +250,8 @@ gofakeit.AddFuncLookup("friendname", gofakeit.Info{
229250
Description: "Random friend name",
230251
Example: "bill",
231252
Output: "string",
232-
Generate: func(r *rand.Rand, m *gofakeit.MapParams, info *gofakeit.Info) (any, error) {
233-
return gofakeit.RandomString([]string{"bill", "bob", "sally"}), nil
253+
Generate: func(f *Faker, m *gofakeit.MapParams, info *gofakeit.Info) (any, error) {
254+
return f.RandomString([]string{"bill", "bob", "sally"}), nil
234255
},
235256
})
236257

@@ -243,14 +264,14 @@ gofakeit.AddFuncLookup("jumbleword", gofakeit.Info{
243264
Params: []gofakeit.Param{
244265
{Field: "word", Type: "string", Description: "Word you want to jumble"},
245266
},
246-
Generate: func(r *rand.Rand, m *gofakeit.MapParams, info *gofakeit.Info) (any, error) {
267+
Generate: func(f *Faker, m *gofakeit.MapParams, info *gofakeit.Info) (any, error) {
247268
word, err := info.GetString(m, "word")
248269
if err != nil {
249270
return nil, err
250271
}
251272

252273
split := strings.Split(word, "")
253-
gofakeit.ShuffleStrings(split)
274+
f.ShuffleStrings(split)
254275
return strings.Join(split, ""), nil
255276
},
256277
})
@@ -301,7 +322,7 @@ Additional Available Functions
301322
### Example Usages
302323

303324
```go
304-
import "github.com/brianvoe/gofakeit/v6"
325+
import "github.com/brianvoe/gofakeit/v7"
305326

306327
func main() {
307328
// Accessing the Lines variable from within the template.
@@ -748,10 +769,14 @@ ProgrammingLanguageBest() string
748769

749770
```go
750771
Number(min int, max int) int
772+
Int() int
773+
IntN(n int) int
751774
Int8() int8
752775
Int16() int16
753776
Int32() int32
754777
Int64() int64
778+
Uint() uint
779+
UintN(n uint) uint
755780
Uint8() uint8
756781
Uint16() uint16
757782
Uint32() uint32
@@ -762,12 +787,7 @@ Float64() float64
762787
Float64Range(min, max float64) float64
763788
ShuffleInts(a []int)
764789
RandomInt(i []int) int
765-
HexUint8() string
766-
HexUint16() string
767-
HexUint32() string
768-
HexUint64() string
769-
HexUint128() string
770-
HexUint256() string
790+
HexUint(bitsize int) string
771791
```
772792

773793
### String

0 commit comments

Comments
 (0)