Source file src/crypto/rand/example_test.go
1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package rand_test 6 7 import ( 8 "crypto/rand" 9 "fmt" 10 "math/big" 11 ) 12 13 // ExampleInt prints a single cryptographically secure pseudorandom number between 0 and 99 inclusive. 14 func ExampleInt() { 15 a, err := rand.Int(rand.Reader, big.NewInt(100)) 16 if err != nil { 17 fmt.Println("error:", err) 18 return 19 } 20 fmt.Println(a.Int64()) 21 } 22 23 func ExampleRead() { 24 // Note that no error handling is necessary, as Read always succeeds. 25 key := make([]byte, 32) 26 rand.Read(key) 27 } 28