github.com/searKing/golang/go@v1.2.117/crypto/rand/bytes_math.go (about) 1 // Copyright 2020 The searKing Author. 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 6 7 import "math/rand" 8 9 // BytesCrypto returns securely generated random bytes. 10 // It will return an error if the system's secure random 11 // number generator fails to function correctly, in which 12 // case the caller should not continue. 13 func BytesMath(n int) []byte { 14 b := make([]byte, n) 15 rand.Int() 16 _, err := rand.Read(b) 17 // Note that err == nil only if we read len(b) bytes. 18 if err != nil { 19 for i := range b { 20 b[i] = byte(seededRandMath.Int() & 0xFF) 21 } 22 } 23 24 return b 25 }