Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
4230dd4c
Commit
4230dd4c
authored
Aug 08, 2012
by
Yves Junqueira
Committed by
Andrew Gerrand
Aug 08, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto/rand: Example for Read.
R=adg, remyoudompheng, rsc, r CC=golang-dev
https://golang.org/cl/6457085
parent
bacccefa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
src/pkg/crypto/rand/example_test.go
src/pkg/crypto/rand/example_test.go
+29
-0
No files found.
src/pkg/crypto/rand/example_test.go
0 → 100644
View file @
4230dd4c
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
rand_test
import
(
"bytes"
"crypto/rand"
"fmt"
"io"
)
// This example reads 10 cryptographically secure pseudorandom numbers from
// rand.Reader and writes them to a byte slice.
func
ExampleRead
()
{
c
:=
10
b
:=
make
([]
byte
,
c
)
n
,
err
:=
io
.
ReadFull
(
rand
.
Reader
,
b
)
if
n
!=
len
(
b
)
||
err
!=
nil
{
fmt
.
Println
(
"error:"
,
err
)
return
}
// The slice should now contain random bytes instead of only zeroes.
fmt
.
Println
(
bytes
.
Equal
(
b
,
make
([]
byte
,
c
)))
// Output:
// false
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment