It's a very common question among the ordinary people seeking to know the god.but the matter of disasters is perfectly clear and solved for Islamic researchers and religious leaders.the short answer is:all the things in word,including the amount of trees in any province in any country in any year (past or future) is decided by god's will ,all the atoms are created by him and nothing can happen against his will.so disasters with huge amount of casualties (or even with no harm) are created by god,and keep in mind our world(earth) is not the heaven so there is no agreement between us and the god to keep this place safe.we can say almost all of them(including all the wars) are punishments for people.world war II was certainly a punishment for all the euro citizens to live in fear and sadness.earthquakes,like recent japanese one,or back in 2003 ,what happened in Bam ,were also punishments for sure.these happens when the majority of populace of a city or town or country lost their pure believe in god in their hearts and usually they become addicted to some sins.then god will allow them to live and rebuild their society for a long moment(like some months.) then if there remains no hope of turning to a healthy society ,its god who make it a better place by sending a disaster between those.its not god the one who is doing a bad thing,its the very society .a corrupt society can't be live on the earth ,cause it's a god will to have them destroyed completely after some time.So we have many scientific reasons for an earthquake or a flood,and Islam accept this fact.but also islam says that:all of these incredible disasters and events are created by god,and because god is perfect he doesn't need to torture his own creatures for no reason,and also according to clear scripts and sentences of holy quran(the book which is completely guarding by angels) there is no doubt that disasters are punishments for corrupted societies.and keep in mind god has no need to kill a corrupt person right after he makes a big sin .according to Quran,god will allow some people to live and make more and more sins until their society become like them.and also according to quran its unfair to kill them soon,cause maybe they finally find their way.also its against the plan of god for the people cause he wants to test us,not to destroy us as soon as possible.but in here (Quran 57:22,23 and 24) we have another reason for some disasters.it says that for some people(even very good and religious ones) the plan is to have them tested with some sad and harmful event.let us have it:
No disaster strikes upon the earth or among yourselves except that it is in a register before We bring it into being - indeed that, for Allah , is easy -*In order that you not despair over what has eluded you and not exult [in pride] over what He has given you. And Allah does not like everyone self-deluded and boastful -*[Those] who are stingy and enjoin upon people stinginess. And whoever turns away - then indeed, Allah is the Free of need, the Praiseworthy.
Quran 57:22,23 and 24