File tree 1 file changed +19
-5
lines changed
1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -12,16 +12,30 @@ import (
12
12
13
13
// ExampleInt prints a single cryptographically secure pseudorandom number between 0 and 99 inclusive.
14
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
- }
15
+ // Int cannot return an error when using rand.Reader.
16
+ a , _ := rand .Int (rand .Reader , big .NewInt (100 ))
20
17
fmt .Println (a .Int64 ())
21
18
}
22
19
20
+ // ExamplePrime prints a cryptographically secure pseudorandom 64 bit prime number.
21
+ func ExamplePrime () {
22
+ // Prime cannot return an error when using rand.Reader and bits >= 2.
23
+ a , _ := rand .Prime (rand .Reader , 64 )
24
+ fmt .Println (a .Int64 ())
25
+ }
26
+
27
+ // ExampleRead prints a cryptographically secure pseudorandom 32 byte key.
23
28
func ExampleRead () {
24
29
// Note that no error handling is necessary, as Read always succeeds.
25
30
key := make ([]byte , 32 )
26
31
rand .Read (key )
32
+ // The key can contain any byte value, print the key in hex.
33
+ fmt .Printf ("% x\n " , key )
34
+ }
35
+
36
+ // ExampleText prints a random key encoded in base32.
37
+ func ExampleText () {
38
+ key := rand .Text ()
39
+ // The key is base32 and safe to display.
40
+ fmt .Println (key )
27
41
}
You can’t perform that action at this time.
0 commit comments