Не работает не rand(), а imagecolorallocatealpha для форматов изображения не понимающих альфа-канал.
php.net/manual/ru/function.imagecolorallocatealpha.php - When working with transparency, avoid imagecreate() and use imagecreatetruecolor() instead. Transparency effects may not work as expected within a palette-based image.