package gnet

import (
	cryptoRand "crypto/rand"
	"math"
	"math/rand/v2"
)

type randsDefault struct{}

func (r *randsDefault) Int() int {
	return rand.Int()
}

// IntN It panics if n <= 0. see rand.IntN
func (r *randsDefault) IntN(n int) int {
	return rand.IntN(n)
}

func (r *randsDefault) Int8() int8 {
	return int8(rand.IntN(math.MaxInt8))
}

func (r *randsDefault) Int16() int16 {
	return int16(rand.IntN(math.MaxInt16))
}

func (r *randsDefault) Int32() int32 {
	return rand.Int32()
}

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

func (r *randsDefault) Int64N(n int64) int64 {
	return rand.Int64N(n)
}

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

func (r *randsDefault) Uint32() uint32 {
	return rand.Uint32()
}

func (r *randsDefault) Uint16() uint16 {
	return uint16(rand.UintN(math.MaxUint16))
}

func (r *randsDefault) Uint8() uint8 {
	return uint8(rand.UintN(math.MaxUint8))
}

func (r *randsDefault) UintN(n uint) uint {
	return rand.UintN(n)
}

func (r *randsDefault) Uint() uint {
	return rand.UintN(math.MaxUint64)
}

func (r *randsDefault) Float32() float32 {
	return rand.Float32()
}

func (r *randsDefault) Float64() float64 {
	return rand.Float64()
}

func (r *randsDefault) Strings() string {
	return cryptoRand.Text()
}

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

var (
	Rand = &randsDefault{}
)
