包兰特
import "math/rand"func Read
func Read(p []byte) (n int, err error)读取从默认源生成len(p)个随机字节,并将它们写入p。它总是返回len(p)和nil错误。
f unc(* Rand)读
func (r *Rand) Read(p []byte) (n int, err error)读取生成len(p)个随机字节并将其写入p。它总是返回len(p)和nil错误。
例如,
package mainimport ( "math/rand" "fmt")func main() { token := make([]byte, 4) rand.Read(token) fmt.Println(token)}输出:
[187 163 35 30]



