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

refactor(generic): add a seed to the Shuffle method #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mateusfdl
Copy link
Collaborator

What?

Why?

How?

@mateusfdl mateusfdl requested review from thefuga, joaofnds and regiszanandrea and removed request for thefuga January 25, 2023 04:14
@codecov-commenter
Copy link

Codecov Report

Base: 98.18% // Head: 98.19% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (64cc264) compared to base (60d95f9).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #91   +/-   ##
=======================================
  Coverage   98.18%   98.19%           
=======================================
  Files           7        7           
  Lines        1103     1106    +3     
=======================================
+ Hits         1083     1086    +3     
  Misses         14       14           
  Partials        6        6           
Impacted Files Coverage Δ
generic.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@mateusfdl mateusfdl changed the title add pseudo random seed to the pseudo random Shuffle refactor(generic): add a seed to the Shuffle method Jan 25, 2023
@joaofnds
Copy link
Collaborator

I think we should either add a new method that accepts a seed or leave it to the user to set the seed on rand directly, like this:

rand.Seed(time.Now().UnixNano())
collections.Shuffle(slice)

@mateusfdl
Copy link
Collaborator Author

mateusfdl commented Jan 25, 2023

I think we should either add a new method that accepts a seed or leave it to the user to set the seed on rand directly, like this:

rand.Seed(time.Now().UnixNano())
collections.Shuffle(slice)

I strongly disagree. This approach couples the client to generate their seed through the rand package. We added a layer of abstraction on top of rand.Shuffle, passing a callback through the collection.Shuffle we are not telling the client the details of the Shuffle implementation, and it allows them to create their seed mechanism

@joaofnds
Copy link
Collaborator

This is the way Go developers are used to doing things with rand. It is, IMO, the approach that causes the least surprise to Go developers.

@mateusfdl
Copy link
Collaborator Author

My first thought was: it ain't the "go way". On the other hand, I realized this approach forces the client to set it explicitly; otherwise, it will use the default seed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants