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 send a mon who can hit the hardest (except in some cases, the gym leader is most likely to save his / her Ace for the last).
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.
I'll take another case. Imagine you have a Sharpedo with Ice Beam. It knocks out pretty much everyone except Skarmory. Winona leads with Swablu, and in this case, she sends out Skarmory.
This is how it works xD
Hope I helped.