Bulbapedia says it's determined by an "independent value", so how does that value work? Is it simply a variable that's randomly set to something from 0 to 27? How do they make sure Unowns don't change form when transferred from generations 2 or 3 to a newer game? Please don't question my curiosity.
Alternate forms are stored at offset 0x40 of the Pokémon structure. Each form follows the pattern of index << 3 where index starts at zero for the main form.
source and table for Unown forms