github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/crypto/rand/rand.go (about)

     1  // Copyright 2010 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package rand implements a cryptographically secure
     6  // random number generator.
     7  package rand
     8  
     9  import "io"
    10  
    11  // Reader is a global, shared instance of a cryptographically
    12  // secure random number generator.
    13  var Reader io.Reader
    14  
    15  // Read is a helper function that calls Reader.Read using io.ReadFull.
    16  // On return, n == len(b) if and only if err == nil.
    17  func Read(b []byte) (n int, err error) {
    18  	if Reader == nil {
    19  		panic("no rng")
    20  	}
    21  
    22  	return io.ReadFull(Reader, b)
    23  }