mirror of https://github.com/golang/go.git
crypto/rand: add example for Int
This commit is contained in:
parent
586e205522
commit
ef20578884
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue