Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new constructor to faker #132

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions faker.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ func NewWithSeed(src rand.Source) (f Faker) {
return
}

// NewWithSeedNumber returns a new instance of Faker instance with a given seed
func NewWithSeedNumber(src int64) (f Faker) {
generator := rand.New(rand.NewSource(src))
f = Faker{Generator: generator}
return
}

// Blood returns a fake Blood instance for Faker
func (f Faker) Blood() Blood {
return Blood{&f}
Expand Down
7 changes: 7 additions & 0 deletions faker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package faker

import (
"fmt"
"math"
"math/rand"
"reflect"
"strings"
Expand Down Expand Up @@ -81,6 +82,12 @@ func TestNewWithSeed(t *testing.T) {
Expect(t, fmt.Sprintf("%T", f), "faker.Faker")
}

func TestNewWithSeedNumber(t *testing.T) {
number := rand.Int63n(math.MaxInt64)
f := NewWithSeedNumber(number)
Expect(t, fmt.Sprintf("%T", f), "faker.Faker")
}

func TestRandomDigit(t *testing.T) {
f := New()
value := f.RandomDigit()
Expand Down