sethvargo/go-diceware

Add ability to seed the random number generator?

Closed this issue · 1 comments

Ahoy! Great project, very useful, thanks.

It seems like this would be more testable if you used dependency injection so that users can pass in their own random number generator. In my case, I'd like to set the seed. Happy to send a PR if you agree.

The way we usually solve this is by making the entire library mockable: https://pkg.go.dev/github.com/sethvargo/go-diceware@v0.2.1/diceware#NewMockGenerator. Then you don't have to worry about seeding random or flakey tests. You can write your own mocker too, just implement the DicewareGenerator interface on any struct.