2016-07-22 18:15:38 +00:00
|
|
|
// Copyright 2010 The Go Authors. All rights reserved.
|
2010-12-03 04:34:57 +00:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
// Package rand implements a cryptographically secure
|
2018-09-24 21:46:21 +00:00
|
|
|
// random number generator.
|
2010-12-03 04:34:57 +00:00
|
|
|
package rand
|
|
|
|
|
2011-12-03 02:17:34 +00:00
|
|
|
import "io"
|
2010-12-03 04:34:57 +00:00
|
|
|
|
|
|
|
// Reader is a global, shared instance of a cryptographically
|
2018-09-24 21:46:21 +00:00
|
|
|
// secure random number generator.
|
2015-10-31 00:59:47 +00:00
|
|
|
//
|
2022-02-11 14:53:56 -08:00
|
|
|
// On Linux, FreeBSD, Dragonfly and Solaris, Reader uses getrandom(2) if
|
|
|
|
// available, /dev/urandom otherwise.
|
|
|
|
// On OpenBSD and macOS, Reader uses getentropy(2).
|
2016-07-22 18:15:38 +00:00
|
|
|
// On other Unix-like systems, Reader reads from /dev/urandom.
|
2020-12-23 09:57:37 -08:00
|
|
|
// On Windows systems, Reader uses the RtlGenRandom API.
|
2018-09-24 21:46:21 +00:00
|
|
|
// On Wasm, Reader uses the Web Crypto API.
|
2010-12-03 04:34:57 +00:00
|
|
|
var Reader io.Reader
|
|
|
|
|
2013-11-06 19:49:01 +00:00
|
|
|
// Read is a helper function that calls Reader.Read using io.ReadFull.
|
|
|
|
// On return, n == len(b) if and only if err == nil.
|
|
|
|
func Read(b []byte) (n int, err error) {
|
|
|
|
return io.ReadFull(Reader, b)
|
|
|
|
}
|