Newer
Older
activity-manager / src / Helper / StringGenerationHelper.php
@Kilian Riou Kilian Riou on 25 Mar 2021 554 bytes Fix string generator
<?php
namespace App\Helper;

/**
 * Helper to generate strings
 */
class StringGenerationHelper
{

    /**
     * Generate an random string
     *
     * @param array $base Charset to generate the random string
     * @param int $length Length of the random string
     * @return string
     */
    public static function generateString(array $base, int $length): string
    {
        $output = '';
        for ($index = 0; $index < $length; $index ++) {
            $output .= $base[rand(0, count($base) - 1)];
        }

        return $output;
    }
}