Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
Return rand.Rand in place of util.randGen. The type util.randGen was only used to provide a Read method as an alternative to using the rand.Rand read method.
  • Loading branch information
gammazero committed Jul 29, 2024
1 parent 4ec933f commit 679f47e
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,20 @@ func ExpandPathnames(paths []string) ([]string, error) {
return out, nil
}

type randGen struct {
rand.Rand
}

// NewTimeSeededRand returns a random bytes reader
// which has been initialized with the current time.
//
// Deprecated: use github.com/ipfs/go-test/random instead.
func NewTimeSeededRand() io.Reader {
src := rand.NewSource(time.Now().UnixNano())
return &randGen{
Rand: *rand.New(src),
}
return NewSeededRand(time.Now().UnixNano())
}

// NewSeededRand returns a random bytes reader
// initialized with the given seed.
//
// Deprecated: use github.com/ipfs/go-test/random instead.
func NewSeededRand(seed int64) io.Reader {
src := rand.NewSource(seed)
return &randGen{
Rand: *rand.New(src),
}
}

func (r *randGen) Read(p []byte) (n int, err error) {
for i := 0; i < len(p); i++ {
p[i] = byte(r.Rand.Intn(255))
}
return len(p), nil
return rand.New(rand.NewSource(seed))
}

// GetenvBool is the way to check an env var as a boolean
Expand Down

0 comments on commit 679f47e

Please sign in to comment.