Merge pull request #1892 from stevvooe/use-math-rand-reader

testutil, storage: use math/rand.Read where possible
This commit is contained in:
Richard Scothern 2016-08-11 10:04:36 -07:00 committed by GitHub
commit baca174469
3 changed files with 3 additions and 8 deletions

View file

@ -1168,10 +1168,7 @@ func randomFilename(length int64) string {
var randomBytes = make([]byte, 128<<20) var randomBytes = make([]byte, 128<<20)
func init() { func init() {
// increase the random bytes to the required maximum _, _ = rand.Read(randomBytes) // always returns len(randomBytes) and nil error
for i := range randomBytes {
randomBytes[i] = byte(rand.Intn(2 << 8))
}
} }
func randomContents(length int64) []byte { func randomContents(length int64) []byte {

View file

@ -2,7 +2,6 @@ package storage
import ( import (
"bytes" "bytes"
"crypto/rand"
"io" "io"
mrand "math/rand" mrand "math/rand"
"os" "os"
@ -16,7 +15,7 @@ import (
func TestSimpleRead(t *testing.T) { func TestSimpleRead(t *testing.T) {
ctx := context.Background() ctx := context.Background()
content := make([]byte, 1<<20) content := make([]byte, 1<<20)
n, err := rand.Read(content) n, err := mrand.Read(content)
if err != nil { if err != nil {
t.Fatalf("unexpected error building random data: %v", err) t.Fatalf("unexpected error building random data: %v", err)
} }

View file

@ -3,7 +3,6 @@ package testutil
import ( import (
"archive/tar" "archive/tar"
"bytes" "bytes"
"crypto/rand"
"fmt" "fmt"
"io" "io"
mrand "math/rand" mrand "math/rand"
@ -46,7 +45,7 @@ func CreateRandomTarFile() (rs io.ReadSeeker, dgst digest.Digest, err error) {
randomData := make([]byte, fileSize) randomData := make([]byte, fileSize)
// Fill up the buffer with some random data. // Fill up the buffer with some random data.
n, err := rand.Read(randomData) n, err := mrand.Read(randomData)
if n != len(randomData) { if n != len(randomData) {
return nil, "", fmt.Errorf("short read creating random reader: %v bytes != %v bytes", n, len(randomData)) return nil, "", fmt.Errorf("short read creating random reader: %v bytes != %v bytes", n, len(randomData))