PHP Optimization, Randomness at work

I stumbled across a piece of code that were acting up, instead of 1048575 possible combinations (0x0 through 0xFFFFF hexadecimal) it varied between 16 distinct combinations … when executed a couple of thousands times in a tight loop. public static function generateBase16Code() { $chars = “0123456789ABCDEF”; srand(); $result = ”; for ($i = 0; $i