Could put a little example about the use of crypto/rand
[1]?
The function Read
has as parameter an array of bytes. Why? If it access to /dev/urandom to get the random data.
func Read(b []byte) (n int, err os.Error)
Could put a little example about the use of crypto/rand
[1]?
The function Read
has as parameter an array of bytes. Why? If it access to /dev/urandom to get the random data.
func Read(b []byte) (n int, err os.Error)
Read
is a helper function that callsReader.Read
.Reader
is defined as:var Reader io.Reader
.crypto/rand/
io.Reader
is the interface that wraps the basicRead
method.Read
reads up tolen(p)
bytes intop
. It returns the number of bytes read (0 <= n <= len(p)
) and any error encountered. Even ifRead
returnsn < len(p)
, it may use all ofp
as scratch space during the call. If some data is available but notlen(p)
bytes,Read
conventionally returns what is available rather than block waiting for more.At the end of the input stream,
Read
returns0, os.EOF
.Read
may return a non-zero number of bytes with a non-nil
err. In particular, aRead
that exhausts the input may return n >0, os.EOF
.io/#Reader
For example, to read the first 16 random bytes,
Using a package
init()
function,crypto/rand
defaults to using/dev/urandom
.crypto/rand/rand.go