Expected behavior: The random headwear should be assigned before the init script runs, thus allowing the mission designer to fully customize the unit's equipment.
Variant: Instead of entering raw commands into the init box, write a script that does the same thing and call it using execVM. This *sometimes* has the same result, but I haven't had this be consistently reproducible.