For what it's worth, this is not the right way to implement such a site. The author notes that there's a collision problem, but pretends it's not a big deal when it actually is. What's the chaining (re-hashing) strategy, and do you really want to pay that cost every time anyone clicks either of the colliding links?
The better implementation is the one that seems stupid, namely start at 1 and increment your link number every time you get a new one. Encode it in something like base 36 (numbers plus lowercase letters), and you're basically done. This method also guarantees that your links are no longer than they need to be.
It's not writing another tinyurl site that's difficult - there are a bunch of other url shortening services out there. Part of it comes down to how long people think you'll last and, so far, tinyurl has outlasted many startups - they'll likely be around well after Twitter has been acquired or replaced by some other service.
Interesting question, how do they make money? I guess they gather a lot of interesting data, because they can monitor who visits pages they don't own (and also which pages get recommended the most, a ka generate the most URL generation requests). Maybe they can sell that data. On the other hand, services that have a hook into the original pages, like Google Analytics, probably gather a lot more data than TinyURL can, so I don't see the advantage for TinyURL?
The better implementation is the one that seems stupid, namely start at 1 and increment your link number every time you get a new one. Encode it in something like base 36 (numbers plus lowercase letters), and you're basically done. This method also guarantees that your links are no longer than they need to be.