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";


        srand((double)microtime()*1000000);


        $i = 0;


        $salt = '' ;





        while ($i < $length)


        {


            $num = rand() % 33;


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


            $salt .= $tmp;


            $i++;


        }


        return $salt;


    }

anyone…

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

http://www.yiiframew…oc/cookbook/31/

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.