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

composer: seed the random number generator #1136

Merged
merged 1 commit into from
Dec 15, 2020

Conversation

ondrejbudai
Copy link
Member

I thought rand in Go is auto-seeded but I was wrong, see [1].
This commit adds seed initialization.

[1]: https://golang.org/pkg/math/rand/#Seed

@bcl
Copy link
Contributor

bcl commented Dec 15, 2020

Where is math/rand being used? I see crypto/rand being used in several places but not math/rand -- they are different :) crypto/rand gets its numbers from getrandom or /dev/urandom and is much better than math/rand which, even with it seeded, has a higher chance of collisions between systems (unlikely with the uses of Nano but still possible if a number of systems all start at the same time).

@ondrejbudai
Copy link
Member Author

I added math/rand here: #1131 I guess I can seed the Manifest() function with crypto/rand...

I thought rand in Go is auto-seeded but I was wrong, see [1].
This commit adds seed initialization.

[1]: https://golang.org/pkg/math/rand/#Seed

Signed-off-by: Ondřej Budai <[email protected]>
@ondrejbudai
Copy link
Member Author

I force-pushed a version with crypto/rand. The global rand.Seed() call that I had before was ugly, I think this is nicer.

Copy link
Member

@teg teg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I agree with Brian, nice to use proper random seed, even if it would not really make a difference for this usecase.

@bcl
Copy link
Contributor

bcl commented Dec 15, 2020

Ha, I was looking at the wrong branch when searching for math/rand use :) Looks good to me.

@ondrejbudai
Copy link
Member Author

osbuild/koji-osbuild#54 and #1135 appeared, otherwise we're green. 💚

@ondrejbudai ondrejbudai merged commit 1dd4eb7 into osbuild:main Dec 15, 2020
@ondrejbudai ondrejbudai deleted the seed branch December 16, 2020 16:20
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