package util

import (
	"crypto/rand"
	"math/big"
)

const (
	Numbers = "0123456789"
	Chars   = Numbers + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
)

func GenerateRandomString(size int) (string, error) {
	d, err := genRandom(Chars, size)

	return d, err
}

func GenerateRandomNumbers(size int) (string, error) {
	d, err := genRandom(Numbers, size)

	return d, err
}

func genRandom(input string, size int) (string, error) {
	data := make([]byte, size)

	for i := 0; i < size; i++ {
		num, err := rand.Int(rand.Reader, big.NewInt(int64(len(input))))
		if err != nil {
			return "", err
		}
		data[i] = input[num.Int64()]
	}

	return string(data), nil
}
