Move rand initialization to image.go.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 23:08:58 +0200
2 files changed,
8 insertions(+),
9 deletions(-)
M
captcha.go
→
captcha.go
@@ -2,12 +2,10 @@ package captcha
import ( "bytes" - "os" - "rand" - "time" - crand "crypto/rand" + "crypto/rand" "github.com/dchest/uniuri" "io" + "os" ) // Standard number of numbers in captcha@@ -15,15 +13,11 @@ const StdLength = 6
var globalStore = newStore() -func init() { - rand.Seed(time.Seconds()) -} - // randomNumbers return a byte slice of the given length containing random // numbers in range 0-9. func randomNumbers(length int) []byte { n := make([]byte, length) - if _, err := io.ReadFull(crand.Reader, n); err != nil { + if _, err := io.ReadFull(rand.Reader, n); err != nil { panic(err) } for i := range n {
M
image.go
→
image.go
@@ -6,6 +6,7 @@ "image/png"
"io" "os" "rand" + "time" ) const (@@ -22,6 +23,10 @@ primaryColor image.NRGBAColor
numWidth int numHeight int dotSize int +} + +func init() { + rand.Seed(time.Seconds()) } // NewImage returns a new captcha image of the given width and height with the