So you've amassed a ton of mounts that you want to show off. What's a wow player to do??? Sure, you can put different mounts on different keybinds, or use a button bar with all your mounts on it, but who really wants to mouse to a button or remember all those keybinds? We have too many keybinds already. What most people in this situation will do is find a way to randomize their mounts. There are many good mount randomization addons available for this purpose, GoGoMount BrokerMounts and MountRandomMount just to name a few, but I like to have a custom-crafted solution for a lot of my WoW UI issues. I like to make my own macros for targetting, CC and handling cooldowns like Soulburn, and so randomizing my mount macro and giving it all the features I would like to have is something I actually enjoy.

Mounts have numbers!
Mounts are located on the mounts tab, which you can open by looking at your spellbook. Mounts are numbered in the standard left-to-right fashion, starting with 1. By passing the appropriate number to a function called CallCompanion(), we can get on any mount from our stables! Note here that there is one annoying problem with managing your mounts: anytime you add a new mount to your collection, these numbers will change. Sometimes they seem to change in odd ways as well, not merely the "shift to the right" you would imagine. Just be aware that if you want to handle things yourself, you'll need to change your macro anytime you add a new mount. Once you get used to parsing the code, it doesn't really take that long.
Into the Code…

Bindpad is awesome!
I use an addon called BindPad to manage my mount macro. Blizzard's default UI for macros only allows macros of up to 255 characters. This is not at all a limitation of the lua language that World of Warcraft runs on, it's just that they didn't design their macro UI to handle macros that are larger. To be honest, this is the only macro I use that approaches shattering this limit. Without BindPad, I would be forced to either give up some features of the macro or run a mount randomization addon. Thanks to BindPad, I can write it myself!
/run local t,z={},GetRealZoneText();local v,s,a,sh,f,sw=(z=="Kelp'thar Forest" or z=="Shimmering Expanse" or z=="Abyssal Depths"),(z=="Strand of the Ancients"), IsAltKeyDown(), IsShiftKeyDown(), IsFlyableArea(), IsSwimming() ;if IsMounted() then Dismount();return elseif UnitInVehicle("player") then VehicleExit();return end if v then t={1} elseif (a and not sh) or sw then t={20} elseif(sh and a)then t={24} elseif (sh and not a) then t={19}elseif not f then t={3,5,8,10,11,12,13,14,15,22,23} else t={16,9}end; if (not (v or a or f or s or sw or sh)) then t[#t+1]=4;t[#t+1]=24;end;CallCompanion("MOUNT",t[random(#t)])
The Mount Macro itself
The first thing this macro does is /run. This directs WoW's macro interpreter to treat the following text as lua code. Lua is a powerful, fast, and efficient language that powers much of World of Warcraft. Anything you interact with in WoW is constructed out of Lua code. Lua powers buttons, mana bars, the minimap and essentially the entire WoW UI. With the power of Lua, addon writers can customize the UI in almost any way imaginable. Even if you're not a programmer, I'm sure you can follow along as I dissect this seemingly intractable block of code.
The next bit of code assigns various variables with values that will determine which mount we will use. local t,z={},GetRealZoneText(); creates a table with no entries, called a null table. It is in this table that we will store a list of the numbers of the mounts we would like to select from based on our current location and any modifier keys we're pressing. This assignment line also puts the value obtained from GetRealZoneText() into the variable z. So, if we were in Dalaran at the time, z would contain the value "Dalaran". Note also the specifier local. This important word tells the lua interpreter that the values we're assigning are local to the code that runs after the /run. These values will only be accessible by the specified variable within this block of code. Outside of this block of code, other functions can indeed have their own values for these exact same variables. In addition, there can be what is called a global context for these variables. It is for this reason that we specify the local tag. We don't want to write over anyone else's global context for these variables (not that anyone else should be using them either).
The next block of code handles assigning all the other variables we'll use in our mounting decision process. local v,s,a,sh,f,sw=(z=="Kelp'thar Forest" or z=="Shimmering Expanse" or z=="Abyssal Depths"),(z=="Strand of the Ancients"), IsAltKeyDown(), IsShiftKeyDown(), IsFlyableArea(), IsSwimming(); simply fills the variables v,s,a,sh,f,sw with the values to the right of the single equals sign. The first value v is set to several text comparisions where z is checked versus several text strings. Remember that z was set to the current zone. Now we're seeing if that zone is either Shimmering Expanse, Abyssal Depths, or Kelp'thar Forest. You may recognize these as the subzones of Vashj'ir. That's exactly what we're putting in the variable v. If we're in one of those zones, then we're in Vashj'ir, and v will be set to true. We're also testing whether the alt key is down, whether we can currently fly, and whether we're currently swimming. These states will determine which mount we choose.
Sir, Please Step Out of the Vehicle
This is my favorite part of the macro, and was probably the inspiration for me to write a macro to do this in the first place. How many times have you been in a World of Warcraft vehicle and wished your mount key would get you out of the vehicle? This part of the macro does just that! if IsMounted() then Dismount();return elseif UnitInVehicle("player") then VehicleExit(); return end handles both dismounting and leaving vehicles. No more fumbling with the mouse to get out of a demolisher or sidecar! The return end then exits the macro if either of these conditions are true. Lua's entire syntax with regard for if statements is actually if (statement) then DoSomething() else DoSomethingElse() end. The keyword end is a required part of that construct, even though in this case the code terminates execution with the return statement.
Decisions, Decisions
Finally we come to where we pick which mount to use based on the contents of all those variables we populated. The first test if v then t={1} simply checks to see if we're in Vashj'ir. If we are, then the value 1 is is put into the table t. Tables can be thought of as arrays, although they are much more powerful. For the purposes of this treatment however, assume that a table works like an array. Just like arrays, tables can contain multiple values for individual elements. We will populate the array t with the values of the mounts we can choose from randomly based on our current location. For the case where we're in Vashj'ir, clearly we'll want to be using the Abyssal Seahorse. Parsing through the rest of the chain of elseifs , one sees that the Sea Turtle will be selected if the alt key is down without the shift key also down OR we're swimming. If both the shift key and the alt key are down, we'll mount the Traveler's Tundra Mammoth. If the shift key without the alt key is held, we'll mount a Sandstone Drake.
Note that all of these assignments thus far have been a single number for the value placed in the table t. Next however, we have the statement elseif not f then t={3,5,8,10,11,12,13,14,15,22,23}. These are the ground mounts we want to select. If we're in a non-flyable area like Tol Barad or a bg, f will be false, as it was set previously to the value of IsFlyableArea(). So when we can't fly, this is a list of the mounts we select. Finally, we have else t={16,9}end. These two mounts are the mounts that will be selected if we can fly.
Low Clearance
Some mounts are just too darn big. As any tauren who has visited Undercity can attest, some mounts will simply not fit through some arches. I have two mounts that impede my ability to travel in some locations. The Black War Mammoth and Traveler's Tundra Mammoth are great mounts, but they will not fit up the stairs in the Strand of the Ancients battleground. These mounts are added as elements to the table t if we're not in Vashj'ir, a flyable area, or Strand of the Ancients. Lastly, CallCompanion("MOUNT",t[random(#t)]) then randomly selects one of the numbers from the table t, and mounts up.
I hope I've given you a sense what goes on in the underpinnings of World of Warcaft's macro and scripting system. Have fun out there, and keep on coding!