Each military city state special unit is set at the beginning of the game. It's selected from the list of UUs of civs that aren't in that particular game.
e.g. If the first city state you encounter offers Legions, you know that Rome isn't in your game.
This is true. Additionally:
1.) If you mouse-over the city-state type (where it says "militaristic") it will tell you which unique unit that city state is specialized in. This is a method of determining which civs are not in the game (see joncnunn's post) well before receiving one of these unique units or seeing another civ with that unique unit.
2.) Supposedly, the militaristic city state will grant you that unit and that unit only from the time you have researched the technology necessary until you have acquired the technology which makes that unit obsolete (you may want to look the UU up in the Civilopedia as some UU's obsolete later than their default counterparts. For example, Berserkers become obsolete with Metallurgy whereas their counterpart, Longswords, become obsolete with Gunpowder.) I say "supposedly because I had a few games where I was trying to maximize the number of Keshiks or Berserkers and they gave me something else instead. It may have been that they give something else if you lack the resource needed, or it may have been before I figured out...
3.)... they only give you that unique unit if you are allied with them. If you are just friendly, they will give you a different random non-unique unit.
4.) Unless something has changed in a patch or mod that I don't have, militaristic city states never specialize in unique units of the ancient era. This is why you never saw the three you had mentioned, rams, slingers, and hoplites, all of which are ancient era units. I've seen many classical era units, ballistas, cataphracts, AFE's, Legions, C-Cavs, Kris, and Mohawks. The one classical era unit that I've NEVER seen are siege towers, and I think they may have been omitted because it would be too advantageous to have them. Similar argument could be made for Keshiks/Camels, but at least they come a bit later.
Hope this helps