<?php

namespace App\Classes;


use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;

final class common
{

    /**
     * @param int $length
     * @return string
     * @throws InternalServerErrorException
     */
    public static function generateRandomHash(int $length = 10): string {
        try {
            return substr(bin2hex(random_bytes(ceil($length / 2))), 0, $length);
        } catch (\Exception $exception){
            throw new InternalServerErrorException('Failed to generate hash for user invitation');
        }

    }
}