From 9f0bea8a2940504b41c889ccd798e8a94448b21a Mon Sep 17 00:00:00 2001 From: xiaost Date: Thu, 7 Apr 2016 18:34:37 +0800 Subject: [PATCH] Tests: backport go1.6 rand.Read for speedup tests --- examples_test.go | 10 +++++++--- reedsolomon_test.go | 10 +++++++--- streaming_test.go | 8 ++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/examples_test.go b/examples_test.go index e44a0260..7ba7407c 100644 --- a/examples_test.go +++ b/examples_test.go @@ -11,9 +11,13 @@ import ( "github.com/klauspost/reedsolomon" ) -func fillRandom(b []byte) { - for i := range b { - b[i] = byte(rand.Int() & 0xff) +func fillRandom(p []byte) { + for i := 0; i < len(p); i += 7 { + val := rand.Int63() + for j := 0; i+j < len(p) && j < 7; j++ { + p[i+j] = byte(val) + val >>= 8 + } } } diff --git a/reedsolomon_test.go b/reedsolomon_test.go index 0e3b9750..2d92a570 100644 --- a/reedsolomon_test.go +++ b/reedsolomon_test.go @@ -236,9 +236,13 @@ func TestOneEncode(t *testing.T) { } -func fillRandom(b []byte) { - for i := range b { - b[i] = byte(rand.Int() & 0xff) +func fillRandom(p []byte) { + for i := 0; i < len(p); i += 7 { + val := rand.Int63() + for j := 0; i+j < len(p) && j < 7; j++ { + p[i+j] = byte(val) + val >>= 8 + } } } diff --git a/streaming_test.go b/streaming_test.go index 7bdc9938..208571b0 100644 --- a/streaming_test.go +++ b/streaming_test.go @@ -119,9 +119,7 @@ func TestStreamEncodingConcurrent(t *testing.T) { func randomBuffer(length int) *bytes.Buffer { b := make([]byte, length) - for i := range b { - b[i] = byte(rand.Int() & 0xff) - } + fillRandom(b) return bytes.NewBuffer(b) } @@ -129,9 +127,7 @@ func randomBytes(n, length int) [][]byte { bufs := make([][]byte, n) for j := range bufs { bufs[j] = make([]byte, length) - for i := range bufs[j] { - bufs[j][i] = byte(rand.Int() & 0xff) - } + fillRandom(bufs[j]) } return bufs }