Skip to content

Commit

Permalink
fix: replace deprecated rand.Seed usage with local random generator
Browse files Browse the repository at this point in the history
  • Loading branch information
marsevilspirit committed Nov 3, 2024
1 parent 44fdfe3 commit 64916c2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions metrics/go-server/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ type GreetTripleServer struct {

func (srv *GreetTripleServer) Greet(_ context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
resp := &greet.GreetResponse{Greeting: req.Name}
rand.Seed(time.Now().UnixNano())
if rand.Intn(101) > 99 { // mock error here
source := rand.NewSource(time.Now().UnixNano())
r := rand.New(source)
if r.Intn(101) > 99 { // mock error here
return nil, errors.New("random error")
}
time.Sleep(10 * time.Millisecond) // mock business delay
Expand Down

0 comments on commit 64916c2

Please sign in to comment.