Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
helpers_Random
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 generateString
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * A utility class focusing on Randomization.
5 *
6 * @author Jérôme Bogaerts <jerome@taotesting.com>
7 *
8 */
9class helpers_Random
10{
11    /**
12     * Generate a random alphanumeric token with a specific $length.
13     *
14     * @param integer $length The length of the token to be generated.
15     * @return string A randomly generated alphanumeric token.
16     */
17    public static function generateString($length)
18    {
19        $token = '';
20        $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
21        $maxIndex = strlen($chars) - 1;
22
23        for ($i = 0; $i < $length; $i++) {
24            $token .= $chars[mt_rand(0, $maxIndex)];
25        }
26
27        return $token;
28    }
29}