package core

import (
	"crypto/rand"
	"encoding/hex"
	"fmt"
)

// RandomHexID generates a random hex string by reading numBytes bytes from
// crypto/rand. The returned string has length numBytes*2.
// Returns an error if numBytes <= 0 or if crypto/rand.Read fails.
func RandomHexID(numBytes int) (string, error) {
	if numBytes <= 0 {
		return "", fmt.Errorf("random_hex_id: numBytes must be > 0, got %d", numBytes)
	}
	b := make([]byte, numBytes)
	if _, err := rand.Read(b); err != nil {
		return "", fmt.Errorf("random_hex_id: failed to read from crypto/rand: %w", err)
	}
	return hex.EncodeToString(b), nil
}
