O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The previous code presents two possibilities on how to generate random numbers. The first option uses the math/rand package, which is cryptographically insecure, and allows us to generate the same sequence with the use of Source with the same seed number. This approach is usually used in tests. The reason for doing so is for the reproducibility of the sequence.

The second option, the cryptographically secure one, is the use of the crypto/rand package. The API uses the Reader to provide the instance of a cryptographically strong pseudo-random generator. The package itself has the default Reader which is usually based on the system-based random number generator.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required