It's based on both. It used to be achievements only, but as you can guess, some people went into games with the idea to do nothing but get achivements. This is turn really screwed up valve's stats system (some people out there have 2,000 pts and a 20:00 longest life), so Valve decided to make a time-based unlocks system. This was so horribly unpopular that valve went back to the acheivemnt system, but they kept the random unlocks for the hats.
I believe that I have now answered two of your questions. It's always nice to have someone inquisitive on these forums, so keep asking!
EDIT: It's still possible to find weapons through random unlocks, but now that valve has a handle on what achievements should be (medic pack was a disaster), it's probably faster just to go to that class and play for an hour or so to get all the achievements you need.










