What do miners do to deserve bitcoin? I know that you get bitcoins by mining, but mining is just lottery, right? What I want to know is what miners do to deserve bitcoins, or the money is just randomly given without requiring someone to work for it?
Miners keep the bitcoin network running


Miners create new bitcoins, but
Bitcoin network adjusts its own mining difficult so that more there are miners less bitcoins each miner receives. This keeps the money supply steady (not inflatory - you simply cannot "print more bitcoins" like you do with fiat currencies as USD). 
Mining requires a lot of power, so miners face the rising cost of electricity and how much you need to invest into mining equipment to have your mining operations profitable.
Miners also confirm bitcoin network transactions. When you send someone bitcoins, miners check that your transaction is genuine and not double-spent attempt.


Here is also related question How does a difficulty increase affect a miner&#39;s income?