crypto/rand: add example for Int

This commit is contained in:
Alan Yee 2025-02-15 18:59:10 -08:00
parent 586e205522
commit ef20578884
1 changed files with 15 additions and 1 deletions

View File

@ -4,7 +4,21 @@
package rand_test
import "crypto/rand"
import (
"crypto/rand"
"fmt"
"math/big"
)
// ExampleInt prints a single cryptographically secure pseudorandom number between 0 and 99 inclusive.
func ExampleInt() {
a, err := rand.Int(rand.Reader, big.NewInt(100))
if err != nil {
fmt.Println("error:", err)
return
}
fmt.Println(a.Int64())
}
func ExampleRead() {
// Note that no error handling is necessary, as Read always succeeds.