Browse Source

Move rand initialization to image.go.

Dmitry Chestnykh 14 years ago
parent
commit
b58457629b
2 changed files with 8 additions and 9 deletions
  1. 3 9
      captcha.go
  2. 5 0
      image.go

+ 3 - 9
captcha.go

@@ -2,12 +2,10 @@ package captcha
 
 
 import (
 import (
 	"bytes"
 	"bytes"
-	"os"
-	"rand"
-	"time"
-	crand "crypto/rand"
+	"crypto/rand"
 	"github.com/dchest/uniuri"
 	"github.com/dchest/uniuri"
 	"io"
 	"io"
+	"os"
 )
 )
 
 
 // Standard number of numbers in captcha
 // Standard number of numbers in captcha
@@ -15,15 +13,11 @@ const StdLength = 6
 
 
 var globalStore = newStore()
 var globalStore = newStore()
 
 
-func init() {
-	rand.Seed(time.Seconds())
-}
-
 // randomNumbers return a byte slice of the given length containing random
 // randomNumbers return a byte slice of the given length containing random
 // numbers in range 0-9.
 // numbers in range 0-9.
 func randomNumbers(length int) []byte {
 func randomNumbers(length int) []byte {
 	n := make([]byte, length)
 	n := make([]byte, length)
-	if _, err := io.ReadFull(crand.Reader, n); err != nil {
+	if _, err := io.ReadFull(rand.Reader, n); err != nil {
 		panic(err)
 		panic(err)
 	}
 	}
 	for i := range n {
 	for i := range n {

+ 5 - 0
image.go

@@ -6,6 +6,7 @@ import (
 	"io"
 	"io"
 	"os"
 	"os"
 	"rand"
 	"rand"
+	"time"
 )
 )
 
 
 const (
 const (
@@ -24,6 +25,10 @@ type CaptchaImage struct {
 	dotSize      int
 	dotSize      int
 }
 }
 
 
+func init() {
+	rand.Seed(time.Seconds())
+}
+
 // NewImage returns a new captcha image of the given width and height with the
 // NewImage returns a new captcha image of the given width and height with the
 // given slice of numbers, where each number must be in range 0-9.
 // given slice of numbers, where each number must be in range 0-9.
 func NewImage(numbers []byte, width, height int) *CaptchaImage {
 func NewImage(numbers []byte, width, height int) *CaptchaImage {