From d7a1261d62f56c98614c161c289ccca85c5ba9b5 Mon Sep 17 00:00:00 2001 From: Alan Yee Date: Fri, 21 Feb 2025 20:37:59 +0000 Subject: [PATCH] crypto/rand: add example for Int Change-Id: I401e6092b1cbbd332406ffa7f923c46de0a3ff49 GitHub-Last-Rev: ef2057888465be3cff7fb60bc6ffe3d7573ec348 GitHub-Pull-Request: golang/go#71773 Reviewed-on: https://go-review.googlesource.com/c/go/+/650035 Auto-Submit: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov Reviewed-by: Dmitri Shuralyov LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Knyszek --- src/crypto/rand/example_test.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/crypto/rand/example_test.go b/src/crypto/rand/example_test.go index f0127749f0..64e38b11ce 100644 --- a/src/crypto/rand/example_test.go +++ b/src/crypto/rand/example_test.go @@ -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. -- 2.51.0