Best practise for code repeated in models????

I have a repeated function in a couple of my models that all it does is generate a random salt string. Instead of repeating this code in each of the models that requires a generated salt, should i create this as a component or widget or module???? Here is the actual function;

private function randomSalt($length)


        $chars = "abcdefghijkmnopqrstuvwxyz023456789";


        $i = 0;

        $salt = '' ;

        while ($i < $length)


            $num = rand() % 33;

            $tmp = substr($chars, $num, 1);

            $salt .= $tmp;



        return $salt;



is it even worth me making this a component or should i just keep it the way i have???

Create a Utils class with a static method.

or a function and include the file with user-defined functions in index.php file.

Pick Utils class as wlepinski suggested if you want a OO-friendly-solution

or even a function


Also you can extend CActiveRecord class with your own class, e.g. MyClass extends CActiveRecord, where MyClass will have a protected function randomSalt. And a couple of your models will extend this class.