yuid

A small, unique, URL-safe ID generator written in Go.
git clone git://git.lair.cx/yuid
Log | Files | Refs | README | LICENSE

mathrand.go (294B)


      1 package yuid
      2 
      3 import "math/rand"
      4 
      5 type InsecureSource struct{}
      6 
      7 func (InsecureSource) Read(p []byte) (n int, err error) {
      8 	var (
      9 		val uint64
     10 		pos int8
     11 	)
     12 
     13 	for n = 0; n < len(p); n++ {
     14 		if pos == 0 {
     15 			val = rand.Uint64()
     16 			pos = 8
     17 		}
     18 		p[n] = byte(val)
     19 		val >>= 8
     20 		pos--
     21 	}
     22 
     23 	return
     24 }