Skip to content

Commit

Permalink
crypto/rand: add example for Int
Browse files Browse the repository at this point in the history
Change-Id: I401e6092b1cbbd332406ffa7f923c46de0a3ff49
GitHub-Last-Rev: ef20578
GitHub-Pull-Request: #71773
Reviewed-on: https://go-review.googlesource.com/c/go/+/650035
Auto-Submit: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Knyszek <[email protected]>
  • Loading branch information
alanyee authored and gopherbot committed Feb 21, 2025
1 parent f24b299 commit d7a1261
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/crypto/rand/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d7a1261

Please sign in to comment.