package ksuid
import (
cryptoRand "crypto/rand"
"encoding/binary"
"io"
"math/rand"
)
var FastRander = newRBG ()
func newRBG() io .Reader {
r , err := newRandomBitsGenerator ()
if err != nil {
panic (err )
}
return r
}
func newRandomBitsGenerator() (r io .Reader , err error ) {
var seed int64
if seed , err = readCryptoRandomSeed (); err != nil {
return
}
r = &randSourceReader {source : rand .NewSource (seed ).(rand .Source64 )}
return
}
func readCryptoRandomSeed() (seed int64 , err error ) {
var b [8 ]byte
if _, err = io .ReadFull (cryptoRand .Reader , b [:]); err != nil {
return
}
seed = int64 (binary .LittleEndian .Uint64 (b [:]))
return
}
type randSourceReader struct {
source rand .Source64
}
func (r *randSourceReader ) Read (b []byte ) (int , error ) {
binary .LittleEndian .PutUint64 (b [:8 ], r .source .Uint64 ())
binary .LittleEndian .PutUint64 (b [8 :], r .source .Uint64 ())
return 16 , nil
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .