all repos — captcha @ b58457629b6e04cfd6d6522edd507bdb6e311e0f

Go package captcha implements generation and verification of image and audio CAPTCHAs.

Move rand initialization to image.go.
Dmitry Chestnykh dmitry@codingrobots.com
Thu, 21 Apr 2011 23:08:58 +0200
commit

b58457629b6e04cfd6d6522edd507bdb6e311e0f

parent

8033b950026ca04f7b511d0f7914bdd003b95a77

2 files changed, 8 insertions(+), 9 deletions(-)

jump to
M captcha.gocaptcha.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.goimage.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