package utils

import (
	"fmt"
	"math"
	"math/rand"
	"time"
)

var (
	s = rand.NewSource(time.Now().UnixNano())
	r = rand.New(s)
)

func Intn(a int) int {
	return r.Intn(a)
}

func GenCaptcha(length int) string {
	max := int32(math.Pow10(length))
	n := rand.New(s).Int31n(max)
	sf := fmt.Sprintf("%%0%dv", length)
	return fmt.Sprintf(sf, n)
}

func Choice(sl []string) (int, string) {
	n := Intn(len(sl))
	return n, sl[n]
}