package ksuid

import (
	cryptoRand 
	
	
	
)

// FastRander is an io.Reader that uses math/rand and is optimized for
// generating 16 bytes KSUID payloads. It is intended to be used as a
// performance improvements for programs that have no need for
// cryptographically secure KSUIDs and are generating a lot of them.
var FastRander = newRBG()

func newRBG() io.Reader {
	,  := newRandomBitsGenerator()
	if  != nil {
		panic()
	}
	return 
}

func newRandomBitsGenerator() ( io.Reader,  error) {
	var  int64

	if ,  = readCryptoRandomSeed();  != nil {
		return
	}

	 = &randSourceReader{source: rand.NewSource().(rand.Source64)}
	return
}

func readCryptoRandomSeed() ( int64,  error) {
	var  [8]byte

	if _,  = io.ReadFull(cryptoRand.Reader, [:]);  != nil {
		return
	}

	 = int64(binary.LittleEndian.Uint64([:]))
	return
}

type randSourceReader struct {
	source rand.Source64
}

func ( *randSourceReader) ( []byte) (int, error) {
	// optimized for generating 16 bytes payloads
	binary.LittleEndian.PutUint64([:8], .source.Uint64())
	binary.LittleEndian.PutUint64([8:], .source.Uint64())
	return 16, nil
}