package gnet

import (
	cryptoRand "crypto/rand"
	"encoding/hex"
	"math/rand"
	"time"
)

type rands struct {
	rand *rand.Rand
}

func (r *rands) Int64() int64 {
	return r.rand.Int63()
}

func (r *rands) Uint64() uint64 {
	return r.rand.Uint64()
}

func (r *rands) Int63n(n int64) int64 {
	return r.rand.Int63n(n)
}

func (*rands) Source() rand.Source {
	return rand.New(rand.NewSource(time.Now().UnixNano()))
}

func (r *rands) String(n int) string {
	return hex.EncodeToString(r.Block(n))
}

func (r *rands) Block(n int) []byte {
	b := make([]byte, n)
	i, _ := cryptoRand.Read(b)
	return b[:i]
}

var (
	Rand = &rands{
		rand: rand.New(rand.NewSource(time.Now().UnixNano())),
	}
)
