Gym leaders basically have their first Pokémon fixed (as we have our first Pokémon in our party). You can't see their Pokémon before sending your first one. From second one onwards, they check your Pokémon and send out theirs which has Super Effective moves. It is not random, they should have some sort of battle intelligence in order to make Gym battles a little tough. If they have none, they would be helpless and send theirs in random.
For example, one Pokémon would be the most powerful, but not sent first by a Gym leader.
Eg. Fortree City Gym - Swablu, Pelipper, Skarmory, Tropious, and Altaria; and Altaria is mentioned by DB in last, Swablu is mentioned at the first. She sends Swablu first, her first Pokemon (I'm talking about my emerald, giving you an example to make you understand) Click this link for details. I'm facing them with Manectric. Swablu fainted with a spark. Since Altaria take neutral damage with electric moves, and also has Earthquake, The gym leader sent Altaria and OHKO'd it.
This is how it works xD
Hope I helped.