'How to generate an entropy using crypto/rand

I am trying to generate an entropy using crypto/rand instead of math/rand, and my entropy needs to be of type io.Reader.

//using math/rand

src := mathrand.NewSource(123)
entropy := mathrand.New(src)

I would appreciate all the suggestions!



Solution 1:[1]

It's right at the top of the package doc: https://pkg.go.dev/crypto/rand#pkg-variables

Reader is a global, shared instance of a cryptographically secure random number generator.

Just use rand.Reader.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adrian